开发者

Errorprovider not going on successfull validation

I have a textbox which do not allow null values. So i handled Validating event for textbox.My code is

private void nullNotAllowed(object sender, System.ComponentModel.CancelEventArgs e)
{
    TextBox txtMain = (TextBox)sender;
    if (txtMain.Text == "")
    {
        errorProvider1.SetError(txtMain, "error");
        e.Cancel = true;
    }
    else
    {
        error开发者_JAVA技巧Provider1.SetError(txtMain, String.Empty);
        e.Cancel = false;
    }
}

now when my textbox is having null value and i press tab, errorprovider pops up and works fine and even the focus is not lost. but now when i correct my values and press tab, focus is lost this time but error provider still remains there only.

Remember, my textbox is in a panel and panel is in a tabControl and tabcontrol is in the form.


you should clear the error in the Validate event handler.

see here (MSDN) for examples and notses, there is a special warning about focus...

http://msdn.microsoft.com/en-us/library/system.windows.forms.control.validating.aspx

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜