Pregunta

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();
}
¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top