Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should the TextBox raise the validating event when Return is clicked?

I'm a bit confused, as far as I remember the Textbox used to launch the Validating event when the used pushed the Enter key after entering the desired text but this is not happening now.

Do you know if this is the expected behavior or not?

Thanks.

like image 203
Ignacio Soler Garcia Avatar asked Oct 19 '25 05:10

Ignacio Soler Garcia


2 Answers

see:Control.Validating Event

Note: If the CausesValidation property is set to false, the Validating and Validated events are suppressed.

like image 101
Bolu Avatar answered Oct 22 '25 05:10

Bolu


I use a method similar to Javed Akram's answer, but instead of calling the Validating function, I just call focus on the parent...

private void TextBox_KeyPress(object sender, KeyPressEventArgs e)
{
    if (e.KeyChar == (char)Keys.Enter)
    {
        (sender as TextBox).Parent.Focus();
    }
}

When the TextBox itself looses focus it will call its own Validating event

like image 27
Josh Stribling Avatar answered Oct 22 '25 06:10

Josh Stribling