title: C# DataGridView Automatically Adding One _Extra_ Row
body: <p>[Microsoft Visual Studio 2008, Windows 7 Professional 64]</p>
  
  <p>I have a <em>C#</em> class that extends <em>DataGridView</em>:</p>
  
  <pre><code>public class DataGridViewTest : DataGridView
  </code></pre>
  
  <p>This class programatically sets the number of <em>columns</em> and <em>rows</em>. </p>
  
  <p>I have a <em>Form</em> application that creates an instance of <em>DataGridViewTest</em> and adds it to a <em>GroupBox</em>.</p>
  
  <p><em>DataGridViewTest</em> defines static members for the number of <em>columns</em> and the number of <em>rows</em>:</p>
  
  <pre><code>private static int NUM_COLUMNS = 2;
  private static int NUM_ROWS = 2;
  </code></pre>
  
  <p>Here is the code that sets everything up:</p>
  
  <pre><code>public DataGridViewTest()
  {
      for (int i = 0; i &lt; NUM_COLUMNS; i++)
      {
          DataGridViewTextBoxColumn column = new DataGridViewTextBoxColumn();
          column.Name = "Column " + i.ToString();
          this.Columns.Add(column);
      }
  
      for (int i = 0; i &lt; NUM_ROWS; i++)
      {
          DataGridViewRow row = new DataGridViewRow();
          Rows.Add(row);
      }
  }
  </code></pre>
  
  <p>As you can see _NUM_ROWS_ is set to <em>2</em>.</p>
  
  <p>When the application runs, however, the <em>DataGridViewTest</em>  shows a data grid with <em>3</em> rows, not <em>2</em>. (Similarly, setting NUM_ROWS to <em>0</em> creates a data grid with <em>1</em> row.)</p>
  
  <p>Why is this <em>extra</em> row being added?</p>
  
  <p>Here is a screenshot:</p>
  
  <p><img src="https://i144.photobucket.com/albums/r177/tackyjan/datagridview_extra_row.png" alt="DataGridView Extra Row"></p>
  
  <p>Thanks!</p>
  
  <p>Jan</p>