单击打开下拉列表(在数据网格视图中)项目 [英] Open dropdown(in a datagrid view) items on a single click
问题描述
如何避免在 DataGridView
中使用的 DropDownButton
上的双击?现在,我可以通过单击两次或更多次来查看 DataGridView
中的下拉项.第一次选择单元格,第二次单击 DropDownButton
箭头时,它显示列表.如何通过单击实现相同的效果?
How can i avoid the double click on a DropDownButton
used within a DataGridView
? Right now I am able to view the drop down items within the DataGridView
by clicking two or more times. First time it selects the cell and second time when I click on the DropDownButton
arrow, it shows the list. How can I achieve the same in a single click?
推荐答案
您可以通过订阅网格的 EditingControlShowing
事件来实现这一点,并在那里获得 ComboBox
You can achieve this by subscribing for the EditingControlShowing
event of the grid and there for control of type ComboBox
ComboBox ctl = e.Control as ComboBox;
ctl.Enter -= new EventHandler(ctl_Enter);
ctl.Enter += new EventHandler(ctl_Enter);
在 Enter 事件中,使用属性
And in the Enter event, use the property
void ctl_Enter(object sender, EventArgs e)
{
(sender as ComboBox).DroppedDown = true;
}
DroppedDown 顾名思义表示是否显示下拉区域,因此无论何时输入控件,都会将其设置为 true 并显示项目,而无需进一步单击.
DroppedDown indicates as the name suggests whether the dropdown area is shown or not, so whenever the control is entered this will set it to true and display the items without the need of further clicks.
这篇关于单击打开下拉列表(在数据网格视图中)项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!