CComboBox problem
-
Hi guys, I'm handling CBN_SELCHANGE message of a CComboBox object in my app. The calling function is said to be OnCbnSelchangeMycombo(). The message has been intercepted successfully whenever an item is selected. The problem I have is that if the combo box style is set as CBS_DROPDOWN, I am not able to correctly get the text of the selected item, the resulted string is an empty string. If the stype is CBS_DROPDOWNLIST, the return text is correct. I tried to get the text using both
GetWindowText()
andUpdateData()
, they return the same thing. Also, I notice the return string will be correct if I select an item using arrow keys. The string is only empty when I select the item by mouse click. Does anybody know why? Thanks alot. -
Hi guys, I'm handling CBN_SELCHANGE message of a CComboBox object in my app. The calling function is said to be OnCbnSelchangeMycombo(). The message has been intercepted successfully whenever an item is selected. The problem I have is that if the combo box style is set as CBS_DROPDOWN, I am not able to correctly get the text of the selected item, the resulted string is an empty string. If the stype is CBS_DROPDOWNLIST, the return text is correct. I tried to get the text using both
GetWindowText()
andUpdateData()
, they return the same thing. Also, I notice the return string will be correct if I select an item using arrow keys. The string is only empty when I select the item by mouse click. Does anybody know why? Thanks alot.You should use the CBS_SELENDOK message. While CB_SELCHANGE does what you want, you get this while a mouse is selecting a item from the list, so you may get multiple selectons before an actual item is selected by the user. If you vote me down, my score will only get lower
-
You should use the CBS_SELENDOK message. While CB_SELCHANGE does what you want, you get this while a mouse is selecting a item from the list, so you may get multiple selectons before an actual item is selected by the user. If you vote me down, my score will only get lower
Thanks Roger, I tried to handle CBS_SELENDOK message and the return string is still an empty string. The handler function looks like below:
void CMyDlg::OnCbnSelendokMycombo() { UpdateData(TRUE); CString szMyCombo; m_MyCombo.GetWindowText(szMyCombo); if (v_szMyCombo.IsEmpty()) return; }
both szMyCombo and v_szMyCombo return empty strings. v_szMyCombo is the CString value variable for the combo box. Again, if I change the combo box style to "Drop List", the return string is correct. Any other ideas?