Validation and Close / Cancel in WinForms
I added a error provider in a form and added some validation logic. But, when I want to cancel and close the form, the form doesn’t close until the error is fixed. The way to fix this to set the Cancel property of the form closing event to be false.
How about if I have a cancel button and would like the same behavior as above? The trick now is to set the CausesValidation property of the cancel button to be false. Now, if you try this and it still doesn’t work, then just make sure that all the (parent) containers, excluding the form, of the cancel button also have the CausesValidation property as false.

Comments