I have an MFC combo box, specifically a type derived from CComboBox
, created as a dropdown list box without the possibility to edit the selected entry, i.e. a simple list of selectable items.
I do support the possibility of none of the items being selected. I know I can just call SetCurSel(-1)
and the edit field of the combo box will be empty until the user selects a "proper" item from the dropdown list. But I would actually prefer to show some kind of default text instead of just an empty field. So what I need to do is set the edit field's text without adding that text to the item list or making the item user-editable.
I tried SetWindowText
on the combo box, without success. Based on a comment suggestion I also tried to use GetComboBoxInfo
to get a handle to the edit box (in the COMBOBOXINFO::hwndItem
) member and calling SetWindowText
on that, but this didn't work either (GetComboBoxInfo
was successful, though). But I can't imagine this to be a particularly odd use case, so maybe it is possible by other means? If it helps, the combo box is actually ownerdrawn (CBS_OWNERDRAWFIXED
).
GetComboBoxInfo
and then useCOMBOBOXINFO.hwndItem
in callSetWindowText
? – RbMmWM_DRAWITEM
as itemID - 1. Something like that anyway, put a breakpoint on it and check. – Paul Sanders