I created an errorProvider on an windows application to validate text boxes.
It works great if I enter something values out side an int range.
I cannot make it work if the box is blank or if I enter characters in the text box.
How can errorProvider validate under these two conditions?
private void buttonAccept_Click(object sender, System.EventArgs e)
{
int pick, totalPick, max;
max = int.Parse(textBoxMax.Text);
totalPick = int.Parse(textBoxPick.Text);
pick = int.Parse(textBoxEnterNumber.Text);
if (countNumber>=totalPick)
{
errorProvider.SetError(textBoxEnterNumber, "You have picked " + totalPick + " the numbers.");
}
else if (pick<1 || pick>max)
{
errorProvider.SetError(textBoxEnterNumber, "You must enter a number from 1 to " + max + ".");
}
//This does not work
else if (textBoxEnterNumber.Text == "")
{
errorProvider.SetError(textBoxEnterNumber, "You must enter a number from 1 to " + max + ".");
}
else
{
countNumber++;
numbers.Add(pick);
textBoxEnterNumber.Clear();
textBoxMessages.Text += "Number" + (countNumber) + ": " + pick.ToString()+"\r\n";
errorProvider.SetError(textBoxEnterNumber, "");
}
}