How can I get the value (string) of the current selection in a combobox?
(Not the integer index)
How can I get the value (string) of the current selection in a combobox?
(Not the integer index)
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()
.
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
--
Michael
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.