clear all errors with ErrorProvider

  • Thread starter Thread starter Tim Chantome
  • Start date Start date
T

Tim Chantome

I want to use a single ErrorProvider for my entire form by adding
control/error combinations using:

myErrorProvider.SetError(textBox1, errorMessage1);
myErrorProvider.SetError(textBox2, errorMessage2);

This works with no problems. However, I want to be able to easily
clear *all* errors that the provider is bound to. I realize that I
can set do this via the following:

myErrorProvider.SetError(textBox1, "");
myErrorProvider.SetError(textBox2, "");

....but since there will be a lot of controls on the page I'm hoping
there's some way to simply clear all.

myErrorProvider.Clear(); //alas, i know this doesn't exist...

anyone have any suggestions?
TIA
 
Hi Tim,

A while ago I was aslo searching for it but couldn't find anything. I just
mode a simple loop to reset all errors, something like this:

foreach(Control cr in this.Controls)
{
errorProvider1.SetError(cr,"");
}

Hope it helps,

greets Gerben
 
thanks for the replies. I hacked up a decent solution by writing a
AddError method that simply adds the control to an ArrayList and then
a ClearErrors method that rips thru each item in the collection and
re-initializes each control's respective error.

This prevents looping thru the entire form's controls collection, and
provides a way to reach nested controls (panels, UCs, tabs, etc).

happy coding...
 
Would would this not work with nested controls? If you put in a routine and
called is recursively passing the parent control would that not work?
 
Back
Top