Autocomplete on Combobox onkeypress event eats Enter key

I have a ComboBox with AutoCompleteMode = suggestand handle a KeyPress event as follows:

private void searchBox_KeyPress(object sender, KeyPressEventArgs e)
{
    if (e.KeyChar == (char)Keys.Return)
    {
        // do stuff
    }
}

However, he does not catch the key Enter. It catches the rest, since the autocomplete drop-down menu works fine.

I also tried the suggestion here: http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/2db0b540-756a-4a4f-9371-adbb92409806 , set the property KeyPreviewto true and put a breakpoint on the form KeyPress Event Handler:

private void Form_KeyPress(object sender, KeyPressEventArgs e)
{
    e.Handled = false;
}

However, even the form handler did not catch the input key!

Any suggestions?

(If I turn off autocomplete, it will catch the Enter key)

+3
source share
1

KeyDown KeyPress

, , KeyDown.

void SearchBox_KeyDown(object sender, KeyEventArgs e)
{
   if(e.KeyCode == Keys.Enter)
    {
        // Do stuff
    }
}

KeyPress: Enter autocompete, combobox !:-)

+4

Source: https://habr.com/ru/post/1786945/


All Articles