3

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

4

4 回答 4

4

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));
}
于 2010-02-19T15:07:50.840 回答
2

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.

于 2008-10-28T18:03:34.897 回答
2

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.

于 2009-10-02T18:55:07.053 回答
1

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.

于 2008-10-01T06:35:44.933 回答