Search code examples
c#.netwinformserrorprovider

Disable Whole Form by Error Provider


In a Windows form I've some controls and a UserControl. I've a ErrorProvider in the UserControl. I want to stop editing all the controls in the Form if there is an error in the userControl. Is there any way to do that?

I am using errorProvider.BindToCustomDataAndErrors(..)


Solution

    1. Expose a property on the user control to indicate whether it has any errors (such as by iterating the control collection and checking errorProvider.GetError(control)

    2. Check your property and disable whatever you need to

      if (!myUserControl.IsValid) { someContainerControl.Enabled = false; }

    3. If you need to be notified in 'real time', declare an event on the user control IsValidChanged, attach to it and disable your controls when it fires and IsValid is false.