将搜索功能添加到MFC组合框 [英] Adding search functionality to a MFC combo box

查看:315
本文介绍了将搜索功能添加到MFC组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我需要创建一个组合框,为用户提供自动搜索功能。它应该像我们在Windows运行对话框或Windows搜索对话框中看到的组合框一样。因此,当用户键入字符时,必须显示组合框列表中的所有匹配字符串。



我这样做的想法如下:



1>每次用户编辑组合编辑框时都会收到通知。

2>在编辑处理程序中,获取组合框中的文本。

3>然后搜索组合框列表中的所有条目,并在列表中构建匹配条目的向量。

4>创建一个填充了向量中的字符串的列表框并显示它(与组合框正确对齐)。



有没有更简单的方法可以做到这一点,还是MFC提供了更简单的方法或任何现成的功能,可以完成上述步骤中提到的所有任务?一些示例代码或链接将有所帮助。

解决方案

请参阅这个 [ ^ ]文章。



文章中提供的控件涵盖了您的所有要求,并支持 CEdit CComboBox 。 :)

参考。对于这篇文章,它可能会帮助你:



http://www.codeguru.com/cpp/controls/combobox/article.php/c4951 [ ^ ]


我自己使用了相同的技术。 MFC不提供任何现成的功能。


Hi,

I need to create a combo box which provides the auto search feature to a user. Its should behave just like the combo box which we see in the Windows 'Run' dialog or in the windows search dialog. So, as the user types in characters , all the matching strings in the combo box list must be displayed.

MY idea for doing this is as follows:

1> Get notified every time the user edits the combo edit box.
2> In the edit handler, get the text in the combobox.
3> Then search through all entries in the combo box list and build a vector of matching entries in the list.
4> Create a list box populated with the strings in the vector and display it (properly aligned with the combo box).

Is there a simpler way of doing this or does MFC provide a simpler way or any ready made functions which can accomplish all the tasks mentioned in the steps above? Some sample code or links will be helpful.

解决方案

Refer to this[^] article.

The control presented in the article covers all of your requirements and supports both CEdit and CComboBox. :)


Ref. to this article, it might help you out:

http://www.codeguru.com/cpp/controls/combobox/article.php/c4951[^]


I myself had used the same technique. MFC doesn't provide any ready made functions.


这篇关于将搜索功能添加到MFC组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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