title: c# datagrid view leaves previous rows blank
body: <p>I'm currently trying to input information into a data grid view, but when I try to do it, if the user has got a cell selected that one won't have a value afterwards, and i fixed this using a refreshedit(); at the end of the loop, however that meant that only the last row was written to at the end</p>
  
  <p>here's the code at the moment </p>
  
  <pre><code>        foreach ( Contact c in currentBook.Contacts )
          {
  
              ContactsList.RowCount = i + 1;
              ContactsList.Rows[ i ].Cells[ 1 ].Value = c.FirstName;
              ContactsList.Rows[ i ].Cells[ 2 ].Value = c.Surname;
              ContactsList.Rows[ i ].Cells[ 3 ].Value = c.Address;
              ContactsList.Rows[ i ].Cells[ 4 ].Value = c.Town;
              ContactsList.Rows[ i ].Cells[ 5 ].Value = c.County;
              ContactsList.Rows[ i ].Cells[ 6 ].Value = c.Postcode;
              ContactsList.Rows[ i ].Cells[ 7 ].Value = c.PhoneNum;
              ContactsList.Rows[ i ].Cells[ 8 ].Value = c.Email;
              i++;
  
          }
  </code></pre>
  
  <p>this code gets an exception saying:
  Operation did not succeed because the program cannot commit or quit a cell value change.</p>
  
  <p>so i added in a</p>
  
  <pre><code>ContactsList.RefreshEdit();
  </code></pre>
  
  <p>after incrementing i however this means only the last row is displayed</p>
  
  <p>I'll be grateful for any help</p>
  
  <p>thanks</p>