Search code examples
.netwinforms.net-2.0

How to determine if the combobox selectionchangecommitted was raised by keyboard or mouse input


I want the ignore the up and down arrow keys on the SelectionChangeCommitted event of a combo box and only have the mouse allow selection. Does anyone know how to do this?

I need a way to determine whether key or click caused the SelectionChangeCommitted event. I guess I could have a flag that turns on in a mouseclick event and off in a key down, but I wondered if there was a cleaner way?


Solution

  • You can suppress the key by using the KeyDown event like this;

        private void comboBox1_KeyDown(object sender, KeyEventArgs e)
        {
            e.SuppressKeyPress = true;
        }