Mr Shoubs
Mr Shoubs

Reputation: 15429

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?

Upvotes: 2

Views: 401

Answers (2)

denolk
denolk

Reputation: 770

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

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

Upvotes: 2

MusiGenesis
MusiGenesis

Reputation: 75396

You should be able to handle the KeyPress event for your combobox, and cancel (e.Canceled = true;) it. This will also prevent the combobox item from changing when you hit a key that matches the first letter of an item.

Upvotes: 2

Related Questions