0
votes

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");
        }
    }
1
When do you need to compare them? On submit, then move the code there and if they dont match return error and it will stop submitting. If it is some other reason do on textbox leave event/loose focus (or whatever the name was) possibly.Brad
You can use the Leave-event: docs.microsoft.com/en-us/dotnet/api/…Tim Schmelter

1 Answers

1
votes

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).