开发者

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

I want the ignore the up and down 开发者_如何学JAVAarrow 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?


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

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜