Reputation: 406
There are several textboxes and the values each one of them increasing sequeantially. I mean
textbox1.Text<textbox2.Text<textbox3.Text<textbbox4.Text<.....
Which event can be used to validate this condtions. In the code below i used textChanged but in the scenario for example the value in the textbox1.Text=30
afterward when istart to type to textbox1.Text
value 5 (which i inteded to enter 59) the focus jump to textbox1
. What is the correct event comparing for two textboxes.
private void textbox2_TextChanged(object sender, EventArgs e)
{
if (double.Parse(textbox1.Text) > double.Parse(textbox2.Text))
{
textbox1.Focus();
errProvider1.SetError(textbox1, "Error");
}
}
Upvotes: 0
Views: 50
Reputation: 519
First of all: Remove the textbox1.Focus(), but keep the visual part of the error (which i suppose are handled by the errorprovider.
It's ok to check the values while the user enters them, but don't interrupt the flow (that is move the focus)!
As Tim suggests, you can move the code to the Leave event, but this might not be fired if the user presses a button (or worse use a shortcut).
Upvotes: 1