tags:

views:

1295

answers:

6

I need a combobox in an Windows MFC application that has a search feature. It should work so that if you start typing something that matches one or more items in the list, the combobox should drop-down and display those items. Kinda like popular ajax-based search boxes on the web

Do you - know of any control that provides this functionality? - have a link to information on how to create such functionality myself? - have ideas on how to do this that you could share?

A: 

Provide a handler for the CBN_EDITCHANGE event, your handler willö be called every time the user changes the text in the edit field.

In this Handler, call the CComboBox::FindString() method to see if the typed text exists in any of your combobox entries. If it does, call CComboBox::SetCurSel() to select it.

Treb
A: 

How do I access the typed text? Can't find an appropriate method.

jonsb
CString text; m_combo1.GetWindowText(text);
baash05
A: 

It's a Win32 api FAQ. See Adv. Win32 api ng news://194.177.96.26/comp.os.ms-windows.programmer.win32 (you don't need at all CBN_EDITCHANGE. It's automatic with api)

A: 

Full access to the edit box of the combo box:

CEdit *pEdit = (CEdit *)pComboBox->GetWindow(GW_CHILD);
Serge - appTranslator
A: 

CEdit *pEdit = (CEdit *)pComboBox->GetWindow(GW_CHILD);

Can I get access to the ListBox part in a similar way? Need to clear the contents of the list, e.g. using ResetContent.

jonsb
+1  A: 

Found this:

http://www.codeguru.com/cpp/controls/combobox/article.php/c1807/

Renamed the class since CComboBoxEx is now part of MFC, and added a ShowDropDown() call in OnEditUpdate().

jonsb