C datagridview cellvalidating example

When you click a Check Box in a Data Grid View Check Box Column, the check marker will update immediately, but Cell Value Changed event on the Data Grid View will not fire until the user happens to click elsewhere and the cell has lost focus. Well, the Data Grid View thinks it’s a little preemptive to go declaring that the cell value has changed while you are still selected on it.This makes more sense when we think about a Text Box column.How can I disable the cell validating event for the rows that was added before???thankxxxxxx There are two ways to manage unwanted execution of event handlers.Also, the drop down list will add / remove handlers so you can easily test out which handlers do what without having to specifically comment out lines of code.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.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).

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.

I’d rather code to do exactly what it says it’s doing. This has the added bonus of not firing when you have clicked outside of the checkbox area, but still falls perhaps under the same category of not being entirely clear to someone unfamiliar with this issue why this particular event should force the grid to exit edit mode.

After looking into the problem at some length, MSDN actually seems to offer the best solution right on their Cell Content Click event page. I like that it tells us very specifically what has happened to the grid at the point in time when the event is raised and handled.

1) Add a conditional statement in the event handler code to only execute when required.

2) Detach the event hander before the unwanted event triggers and re-attach after.

C datagridview cellvalidating example