什么在Keybord上使用SelectedIndexChanged? [英] What to use SelectedIndexChanged on Keybord?

查看:80
本文介绍了什么在Keybord上使用SelectedIndexChanged?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用SelectedIndexChanged?



我在我的WindowsForm中设置了一个Combobox。

然后,如果我用鼠标选择在Combobox下拉列表中的项目,任何问题都会发生。

但我使用keybord选择组合框中的项目,当我按下向下键(也是向上键)时,每次都会发生SelectedIndexChanged事件。 />


我想让我的事件发生在我决定选择Combobox时。

任何建议都没问题。

How to use SelectedIndexChanged?

I set a Combobox in my WindowsForm.
Then, if I use my mouse to select the item on the dropdownlist on Combobox, any problem happens.
But I use keybord to select the item on the combobox, SelectedIndexChanged event happens in everytime when I put the down key(also up key).

I want to make my event happens when I decided the selection on the Combobox.
Any suggestion is OK.

推荐答案

看一下SelectionChangeCommitted事件。这会触发用户启动的选择更改,但不会在下拉列表打开时触发。



请注意,程序选择更改不会触发。所以代码如

combo.SelectedIndex = someNewIndexValue; 将触发SelectedIndexChanged而不是SelectionChangeCommitted。



Alan。
Take a look at the SelectionChangeCommitted event. This fires on user initiated selection changes but not when the dropdown is open.

Be aware that it does not fire for programmatic selection changes. So code such as
combo.SelectedIndex = someNewIndexValue; will fire SelectedIndexChanged but not SelectionChangeCommitted.

Alan.


您可以使用DropDownClosed事件。

它只会在下拉列表关闭时触发。你检查了SelectedItem。



You can use the DropDownClosed event instead.
It will only fire when the dropdown list is closed. The you check the SelectedItem.

private void comboBox1_DropDownClosed(object sender, EventArgs e)
{
    // Convert to to what ever type you have stored
    MyType obj = (MyType)comboBox1.SelectedItem;  
}


这篇关于什么在Keybord上使用SelectedIndexChanged?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆