开发者

How do I display all error messages on a Windows Forms in like a error summary control?

I have a windows forms, and when I hit submit, it'll use the Error Provider class to display a little red error i开发者_高级运维con 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


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.


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);
        }
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜