petre ricardo

petre ricardo

  • NA
  • 194
  • 0

my DataGrid DOESNT display the data?

Mar 15 2010 9:57 PM

Hi friend,
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:
 
private void Form1_Load(object sender, EventArgs e)
{
dataGridView1.AutoGenerateColumns =
false;
DataTable dt = new DataTable("tesr");
DataColumn dcName = new DataColumn("Name", typeof(string));
dt.Columns.Add(dcName);

 
dt.Columns.Add(
"address", typeof(string));
 
DataRow dr = dt.NewRow();
dr[0] =
"Jappa";
dr[1] =
"12, Hector Rd";
dt.Rows.Add(dr);
 
dataGridView1.DataSource = dt;
 
}

But it displays an empty Grid:
 
 
Photobucket
 
Why this happense?
thanks
PS: I have attached the code if required to have a look at it :)
 

Attachment: TestGrid.zip

Answers (3)