I am using a combobox without the dropdown to accept text input only. On the windows form I have an OK button which calls a function that uses the combobox.Text property.
The problem is that I want to call this function when the user types something then hits ENTER. I am trying to handle the KeyDown event (I have tried other events with much the same results) but I find that combobox.Text is null after this is fired. I want something like this to work ideally:
private void cbox_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyValue == 13)
{
OK(cbox.Text);
}
}
Why is combobox.Text wiped after the KeyDown event? This same problem wouldn’t happen with a Textbox right? I’m nearly desperate enough but I don’t want to replace this box on every form in the program lol… Please advise!
Do you have more than one ComboBox on your form? The event is for
cboxbut you are getting the text result fromcbo.I would suggest changing you code to this: