DataGridViewComboBoxColumn没有打开第一次点击的下拉列表 [英] DataGridViewComboBoxColumn doesn't open the dropdown on first click

查看:159
本文介绍了DataGridViewComboBoxColumn没有打开第一次点击的下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在任何人将此标记为重复之前,请注意,这与问题不一致这里这里此处



当您的 DataGridView 中有两个或多个 DataGridViewComboBoxColumn 时,他们的下拉菜单当前打开,点击不同列的下拉式按钮不会打开该下拉菜单。相反,您仍然必须点击两次。首先点击被隐藏已经打开的下拉菜单,第二次点击实际打开您点击的下拉菜单。



请注意,当 EditOnEnter 模式为ON;否则,您必须执行三次点击才能完成此操作。我也尝试过ContentClick事件,没有任何收获。



那么在我的网格中有多个 DataGridViewComboBoxColumn 的情况下,如何使用单击操作?



更新



只要有人想要重现它,这里是进程:


  1. 创建一个新的WinForms C#项目。

  2. 转到Form1的代码,然后粘贴到构造函数中 InitializeComponent line:

      DataGridView dgv = new DataGridView(); 
    DataGridViewComboBoxColumn col1 = new DataGridViewComboBoxColumn();
    DataGridViewComboBoxColumn col2 = new DataGridViewComboBoxColumn();

    dgv.Columns.AddRange(new DataGridViewColumn [] {col1,col2});
    dgv.Dock = DockStyle.Fill;
    dgv.EditMode = DataGridViewEditMode.EditOnEnter;

    col1.Items.AddRange(new object [] {Cat,Dog,Elephant,Lion});
    col2.Items.AddRange(new object [] {Duck,Hen,Crow,Sparrow});

    this.Controls.Add(dgv);


  3. 运行项目。点击第一个下拉菜单,然后点击其他下拉菜单,而不关闭第一个。这将需要2或3次点击(取决于您在第二个下拉列表中点击的位置)才能打开第二个列表。



解决方案

你的代码没有错。这是.NET DataGridView控件的设计行为。



如果您点击下拉控件右侧的按钮(向下箭头),而不是在文本区域,下拉列表将立即显示 - 1点击



如果您点击下拉菜单的文本区域控制,如果将首先获得焦点,然后显示下拉列表 - 2次点击



如果目前还有一个下拉列表展开,那么需要额外的点击来折叠它 - 这将是 3次点击



有几个解决方法来改善这种行为。看看这个MSDN 讨论
IM HO IM HO>>>>>>>>>>>>>>>。。。。。。。。。。。。。。。。。。。。。。。。。。。。>>>>>> /

Before anyone marks this as duplicate, plz note that this is not the same as the questions asked here, here and here.

When you have two or more DataGridViewComboBoxColumns in your DataGridView and one of them has its dropdown currently open, clicking on the dropdown button of a different column does not open that dropdown. Instead you still have to click twice. First click is consumed in hiding the already open dropdown and the second click actually opens the dropdown on which you click.

Note that two clicks are required when EditOnEnter mode is ON; else you'll have to perform three clicks to get this done. I have tried ContentClick event too, without any gain.

So how can I use one-click operation in cases when I have more than one DataGridViewComboBoxColumn in my grid?

Update

Just in case anyone wants to reproduce it, here is the process:

  1. Create a new WinForms C# project.
  2. Go to Form1's code and paste this in the constructor after the InitializeComponent line:

    DataGridView dgv = new DataGridView();
    DataGridViewComboBoxColumn col1 = new DataGridViewComboBoxColumn();
    DataGridViewComboBoxColumn col2 = new DataGridViewComboBoxColumn();
    
    dgv.Columns.AddRange(new DataGridViewColumn[] { col1, col2 });
    dgv.Dock = DockStyle.Fill;
    dgv.EditMode = DataGridViewEditMode.EditOnEnter;
    
    col1.Items.AddRange(new object[] { "Cat", "Dog", "Elephant", "Lion" });
    col2.Items.AddRange(new object[] { "Duck", "Hen", "Crow", "Sparrow" });
    
    this.Controls.Add(dgv);
    

  3. Run the project. Click on the first drop-down, then click on the other dropdown without closing the first one. It will take 2 or 3 clicks (depending upon where you click in the second dropdown) to get the second list opened.

解决方案

There's nothing wrong with your code. This is the designed behavior for the .NET DataGridView control.

If you click on the button (the pointing down arrow) on the right side of the drop down control rather then on the text area, the drop down list will show right away - 1 click.

If you click on the text area of the drop down control, if will get the focus first and then show the drop down list - 2 clicks.

If at the moment another drop down list is expanded then it would take an extra click to collapse it - that would be 3 clicks.

There are a couple of workarounds to improve this behavior. Take a look at this MSDN discussion. IMHO these kinds of alterations are not worth it but it's certainly up to you to decide what suits best to your project.

Best Regards.

这篇关于DataGridViewComboBoxColumn没有打开第一次点击的下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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