我希望用户能够从TComboBox项目中输入第二个或第三个单词,并且该项目将显示在AutoSuggest下拉列表选项中
例如,组合框包含以下项目:
>约翰·布朗先生
>阿曼达·布朗夫人
>布赖恩·琼斯先生
> Samantha Smith夫人
>约翰·布朗先生
>阿曼达·布朗夫人
>布赖恩·琼斯先生
>约翰·布朗先生
>布赖恩·琼斯先生
问题是AutoSuggest功能只包括下拉列表中的项目,从用户输入的内容开始,因此在上述示例中,下拉列表中不会出现任何内容。
可以使用IAutoComplete接口和/或其他相关的接口来解决这个问题吗?
解决方法
以下示例使用插入的
TComboBox
组件类。与原始类的主要区别在于,项目存储在单独的StoredItems属性中,而不是通常为
Items
(由于简单而使用)。
StoredItems被OnChange
事件监视,每当您更改它们(例如通过从该字符串列表中添加或删除)时,即使当Combolist被删除时,当前的过滤器也将反映出来。
这里的要点是抓住WM_COMMAND
消息通知CBN_EDITUPDATE
,每当组合编辑文本更改但尚未呈现时,该消息通知正在发送。当它到达时,您只需搜索StoredItems列表中您在组合编辑中键入的内容,并使用匹配填充Items
属性。
使用ContainsText
进行文本搜索,因此搜索不区分大小写。忘了提及,AutoComplete
功能必须关闭,因为它有自己的,不欢迎的逻辑为此目的。