SOLUTION To achieve data validation prior the row is committed, you can handle the Cell Validating event, which is raised by the control when the current cell changes or when it goes out of edit mode.Canceling this event prevents the user from exiting the cell until a valid value is entered or the edit process is canceled (via Esc key).Note: When i debug code and insert breakpoints on cell Validating event and button.
In this situation the editor is not kept active when the validation fails and pressing the Esc key does not revert the changes as the editor is already closed.
This funtionality can be easily implemented by handling the Preview Key Down event, which will revert the row changes after pressing the Esc key.
The Data Bound Item will be updated only if the cell is validated.
However, the user may prefer to validate all the data cells in a row at once.
This scenario can be achieved by using the Row Validating event, which is fired when the user tries to change the current row (changing to another row or when the control loses focus).
Note that only the Cell Validating event can keep the editor active,when the validation fails and it does not allow the user to exit the cell until a valid value is filled.private void data Grid View1_Cell Validating(object sender, Data Grid View Cell Validating Event Args e) void data Grid View1_Cell End Edit(object sender, Data Grid View Cell Event Args e) And Voila!provides a convenient way to realize data validation before it is committed to the underlying data source.In the Cell End Edit event handler, set the Error Text property on the row to the empty string.The Cell End Edit event occurs only when the cell exits edit mode, which it cannot do if it fails validation.Yeah, I agree with that if it is for validation only.