3
votes

I want to restore the previous value of a cell of a DataGridView. I am currently using the ESC button but I do not want to use it. How can I achieve this?

if (string.IsNullOrEmpty(e.FormattedValue.ToString()))

If this condition is true, I want to re-assign the previou value of the cell and keep control in cell itself. The above code is executed on CellValidating event.

1
How would you like to achieve that then? After the cell edited with a button? using another key? Please provide more details and some code.etaiso
@etaiso No. In the CellValidating event handler, I want to assign te original value if it is changed to nullShaivya Sharma
Find the edited query above with a piece of codeShaivya Sharma

1 Answers

8
votes

Try this:

if (string.IsNullOrEmpty(e.FormattedValue.ToString()))
{
     dataGridView1.CancelEdit();
}