0

I tried to to that as:

private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
    string name = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();    
}

It induces an exception System.NullReferenceException always when I edit cell.

George Alexandria
  • 2,841
  • 2
  • 16
  • 24
ITMANAGER
  • 131
  • 1
  • 3
  • 10
  • 1
    Possible duplicate of [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Fabio Jul 09 '17 at 09:19

1 Answers1

0

There is no error :/ , but to get the changed value you shoud use another Event:

    private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
    {
        String name = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
    }

And every time will be saved changed value in the variable "name" :)

Anouar khaldi
  • 772
  • 6
  • 15
  • Edited value can be save in both event `CellEndEdit` and `CellValidating`. In OP's case there no difference. – Fabio Jul 09 '17 at 09:27
  • no , in Event CellEndEdit the new value will be saved (after Editing) , And if you insist. Can you tell me how ? – Anouar khaldi Jul 09 '17 at 10:05