如何激活下拉框的第一次点击(DataGridView中) [英] How to activate combobox on first click (Datagridview)

查看:152
本文介绍了如何激活下拉框的第一次点击(DataGridView中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在的WinForms,你需要点击两次组合框正确地激活它 - 第一时间关注它,第二次实际得到的下拉列表

In winforms, you need to click the combobox twice to properly activate it - the first time to focus it, the second time to actually get the dropdown list.

我要如何改变这种行为,以便它激活的第一个点击?

How do I change this behavior so that it activates on the very first click?

编辑:哦,天哪......我忘了,这是DataGridView的组合框。我的错。对不起。

Oh god.. I forgot that this is for DATAGRIDVIEW combobox. My mistake. Sorry.

推荐答案

我意识到这是一个老问题,但我想我会给我的解决方案,任何人在那里,可能需要能够做到这一点。

I realize this is an old question, but I figured I would give my solution to anyone out there that may need to be able to do this.

虽然我找不到任何答案,做的正是这个......我没有找到一个回答以不同疑问帮助了我。

While I couldn't find any answers to do exactly this... I did find an answer to a different question that helped me.

这是我的解决方案:

private void datagridview_CellClick(object sender, DataGridViewCellEventArgs e)
    {
        bool validRow = (e.RowIndex != -1); //Make sure the clicked row isn't the header.
        var datagridview = sender as DataGridView;

        // Check to make sure the cell clicked is the cell containing the combobox 
        if(datagridview.Columns[e.ColumnIndex] is DataGridViewComboBoxColumn && validRow)
        {
            datagridview.BeginEdit(true);
            ((ComboBox)datagridview.EditingControl).DroppedDown = true;
        }
    }

以上code必须绑成的datagridview的CellClick事件。

我希望这有助于!

这篇关于如何激活下拉框的第一次点击(DataGridView中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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