I have the following code:
DataTable table = new DataTable();
//DataTable is filled with values here...
DataGridView grid = new DataGridView();
foreach (DataColumn column in table.Columns)
{
grid.Columns.Add(column.ColumnName, column.ColumnName);
}
grid.DataSource = table;
When I examine grid, the DataSource attribute indicates that the number of rows is correct. However, the grid.Rows count is zero.
In contrast, if I create a DataGridView on a winform, and then assign its DataSource to a DataTable, the DataGridView.Rows will be added automatically.
What code am I missing here, in order to have the DataGridView.Rows count correct?
AutoGenerateColumnsproperty?