Governor
Governor

Reputation: 55

Close box triggers validation for non-modal form

I have two form classes inheriting from a common base. One of the forms is called modally and the other non-modally. Validation is required on focus changes but not when the form is cancelled. When the Close Box is selected on the modal form it closes properly without any validation being triggered on it's controls. When the Close Box is selected on the non-modal form, validation events are triggered. A Cancel button with CausesValidation set false works fine in both cases.

I have tried setting CausesValidation on the non-modal form to false but the problem remains. I should mention that the forms are mdi children.

Any ideas?

Thx.

Upvotes: 3

Views: 848

Answers (1)

Rajarshi
Rajarshi

Reputation: 174

Set the "AutoValidate" property of the non-modal form to "Disable". This will prevent the Form from implicitly validating all child controls.

However, at a later time if you require to validate all child controls you can use Form.ValidateChildren() method. That will force validation for all contained child controls.

Upvotes: 3

Related Questions