CComboBox how to use MSVS2010 (C++)

Sorry, I'm lost.  I create a member variable for a CComboBox and called it m_charts.
In CMainFrame implementation I can instantiate CDialog derived object containing this member variable and I can run AddString() to populate it.

So how do I read strings from it?

Here is how far I've gotten.
1.  Class Wizard
2.  Choose my resource IDD_REVEAL_STATE which is the dialog box resource
3.  Pick member variable tab.
4.  Choose the member for the CComboBox
Now what?
I need to start handling messages.  I hope I don't have to subclass again.  Can you help?
Who is Participating?
sarabandeConnect With a Mentor Commented:
you now can add event handlers for the combo box member. do a right-click on the control in resource editor and choose 'Add EventHandler...'. you probably would handle the events CBN_SELCHANGE and CBN_SELENDOK.

to read strings from combo box you could call m_yourcombo.GetCurSel() to get the index of the currently selected item. Then you could get the string m_yourcombo.GetLBText function where you pass the index as input.

supportorangesAuthor Commented:
Thank you, could not remember for the life of me...
the text that is in the editbox of the combobox (either by editing or by selection) can be retrieved by GetWindowText in your dialogs member functions. alternatively, you may add a CString member variable for your combobox in resource editor (right-click + 'Add Variable ...'). then, by UpdateData(TRUE); the CString member was filled with current contents of combobox control from screen (plus all other screen data from controls where you have added a member variable for the value). with UpdateData(FALSE); you can populate your controls from members. that typically is made in OnInitDialog member function.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.