I’m using an ErrorProvider control in winforms project. Its working for the most part (although a bit of a pain to use).
Now I have 2 controls which fire the same validator. In the validator I look at each control and set the error if its wrong. One call works, but the other doesn’t. How can this be? No exception is thrown.
Code:
if (endHour > 12)
{
if (endHour >= 24)
{
//Fails without error
errorProvider1.SetError(lblEnd, "You cannot enter more than 24 hours in a day");
}
else
{
txtEndHour.ForeColor = Color.Blue;
}
}
else
{
errorProvider1.SetError(lblEnd, "");
}
if (endMin >= 60)
{
//Always works.
errorProvider1.SetError(lblEnd, "You can't enter more than 60 minutes in an hour.");
}
else
{
errorProvider1.SetError(lblEnd, "");
}
If you call this code with endHour >= 24 but endMin < 60 you will fall allways to the final else which clears the errorProvider.
You should separate the two validation (better) or put a return when you find the hour part to be invalid.