title: C# DataGridView Cells automatically clearing when selected
body: <p>I have a windows forms application with a DataGridView (DGV) on part of it.  I used the Visual Studio UI to add columns to the DGV and then programmatically added rows with some default values.  My problem is once the rows are added, any cell selected automatically empties whatever value was in it - even read-only cells!</p>
  
  <p>I am only handling the "CellValueChanged" event for the DGV, and all that does is validate the rows to make sure at least one valid combination of values exists and then enables a button.</p>
  
  <p>To add to the confusion, the selected-cell-clearing issue does not always happen. After rows are added, until you make a change or perform an action that reloads the DGV with rows, all the cells will clear.  After that either some or none of the cells will clear on their own.</p>
  
  <p>Has anyone experienced this or know of a way to solve the problem?  All I got from google was "how to make cells clear" and things like that.</p>
  
  <p>Thanks,</p>
  
  <ul>
  <li>Matt</li>
  </ul>
  
  <p><strong>* UPDATE *</strong></p>
  
  <p>Code for adding new rows to the DGV:</p>
  
  <pre><code>        metaMapGrd.Rows.Clear();
          ((DataGridViewComboBoxColumn)metaMapGrd.Columns[1]).DataSource = _excel.ListHeaders(worksheetListCmb.SelectedItem.ToString());
          foreach (Field f in _sharePoint.CurrentFieldList)
          {
              // skip the key field matching portion.  These should be for comparison only.
              if (f.Title == spListKeyCmb.SelectedItem.ToString())
              {
                  continue;
              }
  
              DataGridViewRow row = new DataGridViewRow();
  
              metaMapGrd.Rows.Add(row);
  
              DataGridViewTextBoxCell spcell = new DataGridViewTextBoxCell();
              spcell.Value = f.Title;
              spcell.ToolTipText = f.TypeAsString;
              row.Cells["spListColumn"] = spcell;
  
              DataGridViewCheckBoxCell fcell = new DataGridViewCheckBoxCell();
              fcell.Value = true;
              row.Cells["useThisColumn"] = fcell;
          }
          metaMapGrd.CurrentCell = null;
  </code></pre>