padraigf padraigf -3 years ago 150
C++ Question

Setting selection by text in CComboBox (MFC)

I have a CComboBox of type

DropList
(i.e. it's not editable). What's the easiest way to set the current selection by string?

I know I can use
SetCurSel()
to set it by index, but I want the function to search through the list-items by string and set it.

Answer Source

What about CComboBox::SelectString ?

"Searches for a string in the list box of a combo box, and if the string is found, selects the string in the list box and copies it to the edit control."

https://msdn.microsoft.com/en-us/library/30ft9e54(v=vs.110).aspx

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download