views:

36

answers:

2

I have a windows forms, and when I hit submit, it'll use the Error Provider class to display a little red error icon next to all the fields that are invalidate and display the error message as a tooltip.

Is it easy to have all error messages of the error provider be displayed in like a summary box or a strip on the top of the form?

I know how I would do it in ASP.NEt but am unfamiliar with Windows Forms

+1  A: 

There isn't a control that automatically does this for you. You would have to manually track when errors have been detected or resolved. Once you have a list of the errors then you could easily display them to the user in a list.

See this question I asked a while ago. Hans Passant provided a small helper class that you could use and easily modify.

Barry
+1  A: 

These two methods would gather all the errors for you, recursivly from either a form or user control, the List would be populated with all the error strings

private void geterrors(Form f, List<string> errors)
{
    foreach (Control c in f.Controls)
    {
        geterrors(c, errors);

    }
}

private void geterrors(Control c, List<string> errors)
{
    if (errorProvider1.GetError(c).Length > 0)
    {
        errors.Add(errorProvider1.GetError(c));

        if (c.HasChildren)
        {
            geterrors(c, errors);
        }
    }
}
benPearce