August 6th, 2013, 08:44 AM
Can't set text in Edit Box of ComboBox
I have a Combo Box and when the user selects an item from the dropdown, I want to edit it before it shows up in the Edit Box. So I capture the CBN_SELCHANGE message and I read the user's selection, edit it a bit, and then set it in the Edit Box using ComboBox_SetText(hwndCtl, lpsz) which is equivalent to SetWindowText((hwndCtl), (lpsz)). After I set it I read it back and it is set. However, it does not show up in the Edit Box to the user. The contents of the Edit Box is the dropdown item the user selected and not what I set. I don't understand what I'm doing wrong.
So basically, I'm doing the following:
/* Get index of current selection and the text of that selection. */
int index = SendMessage(m_hRecipients, CB_GETCURSEL, (WORD)0, 0L);
SendMessage(m_hRecipients, CB_GETLBTEXT, (WPARAM)index, (LPARAM)buffer);
//Get current contents of Edit Box
int nLngth = SendMessage(m_hRecipients, WM_GETTEXTLENGTH, NULL, NULL);
csRecipients = (TCHAR *)CoTaskMemAlloc(nLngth);
SendMessage(m_hRecipients, WM_GETTEXT, nLngth+1, (LRESULT)csRecipients);
// concat new selection to contents of Edit Box (current rescipient list)
if (nLngth > 0) tcscat(csRecipients, L",");
// set the new contents of the Edit Box
Can anyone suggest what I'm doing wrong that the Edit Box doesn't persist the contents I set?
Thank you very much,
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!