使用组合框的自动完成功能,同时限制值的列表? [英] Using the AutoComplete feature of ComboBox, while limiting values to those in the list?

查看:158
本文介绍了使用组合框的自动完成功能,同时限制值的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在的WinForms 2.0,组合框有一个自动完成功能,与只有先从输入的文本值显示自定义下拉列表中。

In WinForms 2.0, a ComboBox has an Auto-Complete feature, that displays a custom Drop-Down list with only the values that start with the entered text.

不过,如果我想限制有效值在那些出现在项目组合框的列表中,我能做到这一点通过设置 DropDownStyle 的DropDownList ,从输入值停止用户。

However, if I want to limit valid values to only those that appear in the ComboBox's list of items, I can do that by setting the DropDownStyle to DropDownList, which stops the user from entering a value.

不过,现在我不能使用自动完成功能,该功能需要用户输入。

However, now I can't use the Auto-Complete feature, which requires user input.

有另一种方式来限制输入到列表中,同时还允许使用的自动完成功能?请注意,我已经看到了这方面的一些定制的解决方案,但我真的很喜欢的方式相匹配的自动完成项目显示在一个下拉列表,并进行排序,即使原始列表的可能不大。

Is there another way to limit input to the list, while still allowing use of the Auto-Complete feature? Note that I have seen some custom solutions for this, but I really like the way the matching Auto-Complete items are displayed in a Drop-Down list, and sorted even though the original list may not be.

编辑:我曾想过刚确认输入的数值,即测试用户输入,如果是在,比方说,框TextChanged 事件,甚至使用有效的确证事件。接下来的问题是什么是预期的行为?难道我清楚自己的价值(空值也是无效的),还是我使用默认值?最接近的匹配值?

I have thought about just validating the entered value, i.e. testing user input if it is valid in, say, the TextChanged event, or even using the Validating event. The question then is what is the expected behavior? Do I clear their value (an empty value is also invalid), or do I use a default value? Closest matching value?

P.S。有没有办法,我可以添加到这个问题?

P.s. Is there any other tags that I could add to this question?

推荐答案

您是否尝试过设置 AutoCompleteMode = AutoCompleteMode.SuggestAppend AutoCompleteSource = AutoCompleteSource。 ListItems的?这让用户类型,但它只接受的话是在组合框。唯一的缺点是,行为已更改Win7的(见<一href="http://stackoverflow.com/questions/2001361/combobox-selectedvalue-does-not-match-displayed-text-when-dropdownstyle-dropdow">http://stackoverflow.com/questions/2001361/combobox-selectedvalue-does-not-match-displayed-text-when-dropdownstyle-dropdow).

Have you tried setting AutoCompleteMode = AutoCompleteMode.SuggestAppend and AutoCompleteSource = AutoCompleteSource.ListItems? That lets the user type, but it only accepts words that are in the ComboBox. The only catch is that the behavior has changed for Win7 (see http://stackoverflow.com/questions/2001361/combobox-selectedvalue-does-not-match-displayed-text-when-dropdownstyle-dropdow).

至于标签,你可以尝试组合框和.NET。

As for tags, you might try "combobox" and ".net".

这篇关于使用组合框的自动完成功能,同时限制值的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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