Question

How can I get the value (string) of the current selection in a combobox?

(Not the integer index)

Was it helpful?

Solution

There might be a better way (my MFC is a bit rusty), but it seems like you should be able to call CComboBox::GetLBText(), passing it the current selection using CComboBox::GetCurSel().

OTHER TIPS

A plain old GetWindowText works, too.

Edit: As ajryan points out, GetWindowText actually doesn't work in a CBN_SELCHANGE handler, because the new selection has taken effect but the window text hasn't been updated with the text of the new selection when the WM_COMMAND is sent.

Use GetLBText, passing in the index and a CString object.

edit: too slow!

CB_GETCURSEL return the integer index CB_GETLBTEXT returns string at CB_GETCURSEL

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top