DataGridViewComboBoxColumn没有打开第一次点击的下拉列表 [英] DataGridViewComboBoxColumn doesn't open the dropdown on first click
问题描述
当您的 DataGridView
中有两个或多个 DataGridViewComboBoxColumn
时,他们的下拉菜单当前打开,点击不同列的下拉式按钮不会打开该下拉菜单。相反,您仍然必须点击两次。首先点击被隐藏已经打开的下拉菜单,第二次点击实际打开您点击的下拉菜单。
请注意,当 EditOnEnter
模式为ON;否则,您必须执行三次点击才能完成此操作。我也尝试过ContentClick事件,没有任何收获。
那么在我的网格中有多个 DataGridViewComboBoxColumn
的情况下,如何使用单击操作?
更新
只要有人想要重现它,这里是进程:
- 创建一个新的WinForms C#项目。
-
转到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);
-
运行项目。点击第一个下拉菜单,然后点击其他下拉菜单,而不关闭第一个。这将需要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 DataGridViewComboBoxColumn
s 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:
- Create a new WinForms C# project.
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);
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屋!