如何让 C# Windows 窗体 DropDownList 表现得像浏览器下拉列表?
我有一个处于 DropDownList 模式的组合框。说内容是:
1
2
5
91
92
99
205
在 Forms 应用程序中,我希望能够专注于控件并键入 205 并让它选择 205。相反,我按 2 - 它跳转到 2。我按 0,没有任何内容以 0 开头,因此它保持在 2 。我按 5,它跳到 5。它只查看我按的最后一个键。
同样,如果我输入 99,它会跳转到第一个 9 匹配 - 91,然后跳到第二个 9 匹配 - 92。但我希望它转到 99。
另一方面,在任何浏览器中,如果您在下拉菜单中并输入在字符序列中,它将一起考虑它们并跳转到完整匹配。 (如果您键入文件名,则 Windows 文件夹中的行为相同。)该序列通常会在几秒钟未键入后重置。
如何让我的表单下拉菜单表现得像浏览器下拉菜单一样?
I have a ComboBox in DropDownList mode. Say the contents are:
1
2
5
91
92
99
205
In the Forms application, I want to be able to focus on the control and type 205 and have it select 205. Instead, I press 2 - it jumps to 2. I press 0, nothing starts with 0, so it stays on 2. I press 5, it jumps to 5. It's only looking at the last key I pressed.
Same if I type 99, it jumps to the first 9 match - 91, then to the second 9 match - 92. But I wanted it to go to 99.
On the other hand, in any browser if you are on a dropdown and type in a sequence of characters, it will consider them all together and jump to a full match. (Same behavior in Windows folders if you type a file name.) The sequence usually resets after a few seconds of no typing.
How can I get my forms dropdown to behave like a browser dropdown?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将 AutoCompleteMode 设置为 Suggest,将 AutoCompleteSource 设置为 ListItems,将 Style 设置为 DropDownList。
Set the AutoCompleteMode to Suggest, AutoCompleteSource to ListItems and the Style to DropDownList.
我还要补充一点,您需要将“FlatStyle”属性设置为“Popup”,以使其更像 Web 组合框。
I would also add that you need to set the "FlatStyle" property to "Popup" to make it more like the Web combobox.