title: Programmatically create DataGridview from DataTable
body: <p>I have the following code:</p>
  
  <pre><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;
  </code></pre>
  
  <p>When I examine <code>grid</code>, the <code>DataSource</code> attribute indicates that the number of rows is correct. However, the <code>grid.Rows</code> count is zero.</p>
  
  <p>In contrast, if I create a <code>DataGridView</code> on a winform, and then assign its <code>DataSource</code> to a <code>DataTable</code>, the <code>DataGridView.Rows</code> will be added automatically.</p>
  
  <p>What code am I missing here, in order to have the <code>DataGridView.Rows</code> count correct?</p>