provides a convenient way to realize data validation before it is committed to the underlying data source.
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.
This funtionality can be easily implemented by handling the Preview Key Down event, which will revert the row changes after pressing the Esc key.
Let's assume that the If the user enters empty string for a specific cell and tries to navigate to another row, the validation fails and the Error Text is displayed on the corresponding row.
When the validation fails, the editor is closed, but the user cannot change the current row in the grid until a valid cell value is entered.
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.
When I click on the Cancel button I just want to close the form.
At this point the user is not allowed to cancel the performed changes, pressing the Esc key.
I have a Windows Form with an edit box and a Cancel button. The code is executed every time the edit box loses focus.
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).