I have a form with several textboxes and other controls. I’m using the errorprovider control and I wired the validating event on each textbox that I need to validate. The Validating event occurs when a control yields focus to another control. So the event occurs when you use the tab key to move away from the current control or when you click another control with the mouse1. And I find that extremely annoying, just to give an example, if I open this winform, and then immediately try to close it, it is not going to let me, because the validation will trigger complaining that the first textbox have no text entered.
The behavior I want is using the errorprovider, how can I validate the whole form only when I click the Save button of the form?
Thanks
Check the property Form.AutoValidate.
Possible values:
Setting it to
EnableAllowFocusChangewill resolve the problem of opening the form and immediatly trying to close it since the focus will be transferred to the Cancel button.If you want complete control over the validation you can set it to
Disableand perform manual validation usingForm.ValidateandForm.ValidateChildren. I am not 100% sure but I believe thatForm.ValidateChildrenwill not trigger validation events for controls placed inside aTabControl.