WinForms ComboBox DropDown 和自动完成窗口都出现 [英] WinForms ComboBox DropDown and Autocomplete window both appear

查看:20
本文介绍了WinForms ComboBox DropDown 和自动完成窗口都出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在带有此代码的 winforms 应用程序上有一个 ComboBox:

I've got a ComboBox on a winforms app with this code:

comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems;

DataTable t = new DataTable();
t.Columns.Add("ID", typeof(int));
t.Columns.Add("Display", typeof(string));

for (int i = 1; i < 2000; i++)
{
    t.Rows.Add(i, i.ToString("N0"));
}

comboBox1.DataSource = t;
comboBox1.ValueMember = "ID";
comboBox1.DisplayMember = "Display";

然后我在窗口打开时按照以下步骤操作:

I then follow these steps when the window opens:

  1. 点击ComboBox下拉按钮——这将显示项目列表并选择ComboBox
  2. 中的文本
  3. 输入5"、1"……即我希望使用自动完成功能来搜索 515、516 等.
  4. 您会看到自动完成窗口现在出现在下拉列表的顶部.但是,如果我将鼠标悬停在上方,则接收鼠标事件(包括单击)的是自动完成窗口后面的模糊下拉窗口.所以我想我是点击了一个自动完成项目,但实际上点击了一些我看不到的完全随机的东西.
  1. Click the ComboBox drop down button -- this displays the list of items and selects the text in the ComboBox
  2. Type '5', '1' ... i.e. I'm looking to use autocomplete to search for 515, 516, etc.
  3. You'll see that the autocomplete window now appears ON TOP of the drop down list. However if I mouse over, it's the obscured drop down window behind the autocomplete window that's receiving the mouse events, including the click. So I think I'm clicking on an autocomplete item but actually clicking on something totally random that I can't see.

这是ComboBox 中的错误吗?如果这很重要,我正在使用 Windows 7.我是否以某种方式配置了 ComboBox 错误?

Is this a bug in the ComboBox? I'm using Windows 7 if that matters. Am I configuring the ComboBoxwrong somehow?

另请注意,使用 KEYBOARD 会使用自动完成下拉菜单.所以上/下箭头键使用的是前窗,而鼠标使用的是后窗.

Note also that using the KEYBOARD uses the autocomplete drop down. So up/down arrow keys are using the front window, but the mouse is using the back window.

推荐答案

只需通过从 PropertyGrid 设置属性即可获得此问题的重现.在 Win7 和 Windows XP 中的行为都是如此.

No problem getting a repro for this simply by setting the properties from the PropertyGrid. Behaves this way both in Win7 and Windows XP.

这是这篇反馈文章.如上所述,Microsoft 不考虑修复.一种可能的解决方法是在 DropDown 事件处理程序中禁用自动完成并在 DropDownClosed 事件处理程序中重新启用它.

This is broken behavior documented in this feedback article. As indicated, Microsoft is not considering a fix. One possible workaround is to disable autocomplete in a DropDown event handler and re-enable it in a DropDownClosed event handler.

这篇关于WinForms ComboBox DropDown 和自动完成窗口都出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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