简体   繁体   中英

Textbox validation error provider is not clearing

I have to show an icon to the user if the pressed/typed any wrong characters, so i'm using error_provider.

In my case, the error_provider is not disappearing, if it's a valid number in the textbox. What is the misatek here??

 string text = t_LongitudeRadTextBox.Text;
bool hasDigit = text.Any(letter => Regex.IsMatch(t_LongitudeRadTextBox.Text, "^[0-9]$"));
// Call SetError or Clear on the ErrorProvider.
if (!hasDigit)
{
    errorProvider1.SetError(t_LongitudeRadTextBox, "Needs to contain a digit");
}
else
{
    errorProvider1.Clear();
}

Calling errorProvider1.Clear(); isn't enough as stated in the docs you need to give it an empty string. Like SetError(t_LongitudeRadTextBox, "")

To clear the error message, call the SetError method and pass in Empty for the String value. This removes the error glyph from the specified Control.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM