views:

408

answers:

4

Is it possible to enumerate all the current errors being displayed through an "Error Provider" without having to access the controls?

+1  A: 

There is a summary validator that will give you all of the errors, but it's pretty ugly, and I'm not sure if you can use it without displaying it on the page. Technically, if you are doing things the "right way", all of you error handling should be handled in your midddle teir and then bubbled to the screen that way, so you already have access to all the errors in a collection or dictionary.

Charles Graham
+1  A: 

For any .net WinForms people who find this in google etc...

In WinForms at least enumerating all the current errors being displayed through an "Error Provider" class without accessing all the controls is not possible, there isn't even a summary validator in WinForms.

However if your errors are bubbling up from a lower layer then you should have access to a collection of them somewhere anyway, as the poster Charles Graham points out.

Christopher Edwards
+1  A: 

In WinForms, if your application is simple enough not to have any well-defined "layers" then you could wrap the ErrorProvider in a class that records and exposes all current errors. Or, if the app is really really simple, create a helper method that records/deletes an error and updates the ErrorProvider.

romkyns
A: 

You can get all of the errors from an ErrorProvider by enumerating the Controls collection of its parent and calling GetError on each. Not efficient but it works.

foreach (Control ctrl in errProv.ContainerControl.Controls)
{
    Console.WriteLine(errProv.GetError(ctrl));
}
Aidan Ryan