Do not allow combobox to change the selected option at user input. WITH#

I have a combobox that has focus, if the user types, how can I prevent combobox from changing the selected index.

Say that I have a combo box with options "A" and "B", "A" is selected, and focus is highlighted in the combo box, if the user presses "B", the combo box changes to "B", as I prevent this?

The reason I want to do this is because I use a barcode scanner, and the drop-down list contains a list of printers, the selected printer prints something that scans the barcode scanner. Thus, if I drop out of the drop-down list and the barcode scanner sends input, it changes the selected printer.

This is the first solution I used: I used the keypress event in combobox and set the handled flag to true

private void comboBox_KeyPress(object sender, KeyPressEventArgs e) { e.Handled = true; } 

But this solution does not work for Windows 98.

+4
source share
1 answer

You can save the original selection and then replace it when working with KeyPress.

I would recommend setting the focus on the control before you set the value, or turn off the combo box for the duration of the barcode scan.

+3
source

All Articles