title: Change DataGridView Cell Value Programmatically
body: <p>I have a datagridview which has a datatable as data source. I need to change some cell values manually. For example, if cell input value contains character 'g', it must change "abc" automatically when I leave cell. Following code checks the formatted value of current cell:</p>
  
  <pre><code>private void dgwPNotlar_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
  {
    if (e.ColumnIndex&lt;2||e.ColumnIndex&gt;4||e.FormattedValue.ToString()=="")
    {
      return;
    }
  
    if (e.FormattedValue.ToString().Contains('G')||e.FormattedValue.ToString().Contains('g'))
    {
      dgwPNotlar.EditMode = DataGridViewEditMode.EditProgrammatically;
      dgwPNotlar.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = "abc";
      dgwPNotlar.EndEdit();
      dgwPNotlar.EditMode = DataGridViewEditMode.EditOnEnter;
      return;
    }
  }
  </code></pre>
  
  <p>When the code "dgwPNotlar.EndEdit();" runs, the cell value I changed is "abc", returns to previous value as "g" or "G"..</p>
  
  <p>Any ideas?</p>