clear all errors with ErrorProvider

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
 
G

Gerben van Loon

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
 
T

Tim Chantome

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...
 
J

JerryK

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top