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(..)
You can prevent the user from moving the focus out of the UserControl with the Validating event. For example:
protected override void OnValidating(CancelEventArgs e) {
foreach (Control ctl in this.Controls) {
if (errorProvider1.GetError(ctl) != "") e.Cancel = true;
}
base.OnValidating(e);
}
Using ErrorProvider.GetError() like this is not ideal although it can work. You might want to keep your own list of validation errors.