我如何获得DataGridView的组合框来显示其下拉列表中点击? [英] How do I get DataGridView comboboxes to display their drop down list in one click?

查看:207
本文介绍了我如何获得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,你可以忽略它的<一个href="http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.oneditingcontrolshowing.aspx"相对=nofollow> 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.

这篇关于我如何获得DataGridView的组合框来显示其下拉列表中点击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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