In my application, I have a DataGridView which it's data source varies depening on the button you click. E.G. Clicking 'Total Downloads' it will be:
dataGridView1.DataSource = totalDownloads();
Or the downloads per player
dataGridView1.DataSource = playerDownloads();
Each method obtains data via SQL query and returns a dataTable of this information.
However, with my following code:
dataGridView1.DataSource=getStats();
public DataTable getStats()
{
DataTable table1 = new DataTable("Totals");
table1.Columns.Add("Park Name");
table1.Columns.Add("Author");
table1.Columns.Add("Total Downloads");
table1.Columns[2].DataType = typeof(int);
table1.Columns.Add("Rating (Max 5)");
table1.Columns[3].DataType = typeof(float);
table1.Rows.Add(name,author,download, rating);
}
return table1;
}
I expected to see the colums in the order: "Park Name" "Author" "Total Downloads" "Rating" However, they come in "Downloads", "Park Name", "Author", "Rating"
I've read that adding: dataGridView1.AutoGenerateColumns = false; will fix this...however, this makes no difference to the order at all...
thanks for the help!
For me it did not the trick. One more line needed:
entityDataGridView.AutoGenerateColumns = false;
Regards!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With