我如何获得DataGridView的组合框来显示其下拉列表中点击?
在我设置EditOnEnter是真实的,在的DataGridViewComboBoxCell
仍需要两次点击打开,如果我不点击组合框的向下箭头的一部分。
After I set "EditOnEnter" to be true, the DataGridViewComboBoxCell
still takes two clicks to open if I don't click on the down arrow part of the combo box.
任何人有任何线索如何解决这一问题?我有我自己的的DataGridView
类,我用,这样我就可以很容易地与一些聪明的事件处理程序,希望解决这个问题的全系统。
Anyone have any clue how to fix this? I've got my own DataGridView
class that I use, so I can easily fix this issue system-wide with a few smart event handlers I hope.
感谢。
既然你已经有的DataGridView
的编辑模式
属性设置为EditOnEnter,你可以忽略它的 OnEditingControlShowing
的方法,以确保在下拉列表,一旦显示为一个组合框获得焦点:
Since you already have the DataGridView
's EditMode
property set to "EditOnEnter", you can just override its OnEditingControlShowing
method to make sure the drop-down list is shown as soon as a combo box receives focus:
public class myDataGridView : DataGridView
{
protected override void OnEditingControlShowing(DataGridViewEditingControlShowingEventArgs e)
{
base.OnEditingControlShowing(e);
if (e.Control is ComboBox) {
SendKeys.Send("{F4}");
}
}
}
每当你的的DataGridView编辑控件
控件获得输入焦点,上述code检查,看它是否是一个组合框。如果是这样,它几乎presses 的F4键,这将导致下拉部分扩展(尝试当任何组合框的焦点!)。这是一个黑客的一点点,但它的工作原理就像一个魅力。
Whenever an edit control in your DataGridView
control gets the input focus, the above code checks to see if it is a combo box. If so, it virtually "presses" the F4 key, which causes the drop-down portion to expand (try it when any combo box has the focus!). It's a little bit of a hack, but it works like a charm.