Reputation: 11
The error provider i set for the username is not clearing itself properly. What i understand from my research is that if the SetErrorProvider was appended with an empty string, the error will be cleared itself. However, this does not work in my case. I am using Winform C# and here is my example code.
private void usernamet_Validating(object sender, CancelEventArgs e)
{
ErrorProvider errorProvider = new ErrorProvider();
if (!Regex.IsMatch(usernamet.Text, @"^[a-zA-Z0-9]*$"))
{
e.Cancel = true;
errorProvider.SetError(usernamet, "Username cannot contain special characters.");
}
else
{
e.Cancel = false;
errorProvider.Clear();
errorProvider.SetError(usernamet, "");
errorProvider.SetError(usernamet, null);
errorProvider.SetError(usernamet, string.Empty);
}
}
i have set 4 breakpoints for each example solution i retrieved from my research, however the error is not clearing itself as shown in the pictures.
Upvotes: 1
Views: 177