Datagridview cellvalidating cancel

Rated 3.82/5 based on 744 customer reviews

Unfortunately, this seems to fail if the user has entered invalid data or simply partially entered a row in any way that fails validation.

Cancel only works if all form data is valid, which is obviously problematic.

Most sections contain a Q & A section that answers common questions regarding the specific feature or area covered by the section.

Note that some questions are duplicated in multiple sections based upon the section relevancy.

causes the event to be canceled which blocks the gui. During databinding i have already unsubscribed from this event to disable it.

But now it is still triggered if the user clicks into the cell to edit the invalid value.

So how do I either a) get my button's code to fire before validation or b) determine that the validation was triggered by the button click and bypass it? If you'd like to edit that info into the answer itself I'll accept it immediately.

The Data Grid View control is the new grid control for Windows Froms 2.0.

I also don't see any way to discern from sender/Event Args that my button click triggered validation, so I'm not sure how to discriminate... I'd already tried the stuff you mentioned in your answer but I was missing this one key setting.

Here is what the validation method looks like : to get what you want.

In any case, note that it is better to make sure that the cancellation happens only under the expected conditions; otherwise, the code might get stuck in this event because it is automatically called at many different points.

This almost gets me where I want to be, but the problem is if the user has some invalid data in the cell, the rest of the UI is essentially off-limits until they fix the error or press Esc.

Since pressing Esc might not be intuitive to certain users, they may find it frustrating that they can't e.g.

Leave a Reply