Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CComboBox problem

CComboBox problem

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    J B 0
    wrote on last edited by
    #1

    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() and UpdateData(), 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.

    R 1 Reply Last reply
    0
    • J J B 0

      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() and UpdateData(), 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.

      R Offline
      R Offline
      Roger Allen
      wrote on last edited by
      #2

      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

      J 1 Reply Last reply
      0
      • R Roger Allen

        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

        J Offline
        J Offline
        J B 0
        wrote on last edited by
        #3

        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?

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups