Here my code to create a data table. I must display the columns at form load and even when there is no data so that the user knows what to expect in the dataGridView control... so i have designed the columns for that dataGridView from designer and i have aslo designer the columns for the DataTable from code:
here is my code:
C# |
But it displays an empty Grid:
Why this happense?
thanks
PS: I have attached the code if required to have a look at it :)

Amit ChoudharyRank #145 · 15.8K reputationPosted Mar 15, 2010, 9:04 PM EDT
try this trick
dataGridView1.DataSource = dt.DefaultView;
It'll work fine i have already solved this problem using this trick.
Please mark as answer if it helps.
petre ricardo155 reputationPosted Mar 15, 2010, 10:06 PM EDT
Hirendra SisodiyaRank #258 · 9.8K reputationPosted Mar 15, 2010, 10:19 PM EDT
DataGridView1.AutoGenerateColumns = False;
modify this as
DataGridView1.AutoGenerateColumns = True;
thank you
Please mark as answere, if you like this answere.