I have a datagridview with Cell Validating and Row Validating events handled.
My problem is that when I click into it and then I change my mind and want to cancel edit of the current row these validating methods won't let me do that if it's the first row, it seems to work when there is already some valid rows, but when it's the first it won't let me change the focus to something else.
2) Detach the event hander before the unwanted event triggers and re-attach after. so when i click the add button the cell validating event triggers i have posted the cell validating event do you know how to solve this thanxxx code!!!
EDIT: here is my validating methods: Here is how it looks when it happens, if I hit Escape key, the error message disappears, but when I try to click something else, Row Validation happens again and I back to this state: EDIT2: I use datatable as datasource for this datagridview.
This Data Grid View exists as part of an entry form with a Cancel button.
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.
However, pressing the Esc key in this situation will revert the initial value of the cell and it will close the editor. The Row Validating event has a slightly different behavior.
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.
However, this event is fired every time the user leaves the cell, regardless of whether or not it has changed.
Does Cell Value Changed support a sort of cancel or rollback method to the previous value?
However, I learned that the Cell Value Changed is called prior to Cell End Edit (so is Cell Validation) so I cannot compare old and new value, but I am able to store the old Value in begin Edit and restore the cell value if necessary.