We help IT Professionals succeed at work.

CComboBox

bebonham
bebonham asked
on
two part question.

please, answer both I know part 2 is easy, but I need part one to help me understand c++


1.

please provide example of CComboBox not using the class wiz.

I want basically CComboBox cb;
cb.Create(param)
cb.AddString(value)

CString Answer;
Answer=cb.??


2.

I have CComboBox using class wiz.  I have m_comboValue;

I want it to reflect the value of the combo box when someone updates it.  the member variable using class wiz is not working....how to do this?

I will be glad to post the code if you think I am just being dumb
Thank you, this question is 100 points, because both 1 and 2 are maditory to get the points.
Comment
Watch Question

Commented:
Hi!
1. to get string from combo:
CString Answer;
Answer=cb.GetLBText(cb.GetCurSel(), Answer);
2. to get watch for updating (changing edit text?) you have to handle notification from the combobox CBN_EDITCHANGE in the parent window.
Commented:

1.
There is very little sense of creating a combo box without the wizard. Even if you want to create it dinamicly, you can make one using wizard, position it visualy and make it invisible ( m_cmbDynamicCombo.EnableWindow(FALSE) ) until you actually want to snow it ( m_cmbDynamicCombo.EnableWindow(TRUE) )... In this case, you don't need to call Create().
Anyway, to create it absolutly dynamicly, try this code from your parent window...

CComboBox *m_cmb = new CComboBox;

m_cmb->Create(
      WS_CHILD|WS_VISIBLE|WS_VSCROLL|CBS_DROPDOWNLIST,
      CRect(10,10,200,100), this, 1);
m_cmb->ShowWindow(SW_SHOW   );
// Add something
m_cmb->AddString("String1");
m_cmb->AddString("String2");
m_cmb->AddString("String3");

CString   Answer;

m_cmb->GetWindowText( Answer );


2.
If you have created (using wizard) your combo-member of a type CString, you need to call the

UpdateData(TRUE);

in your dialog every time you want your variable to be actualized with the combo selection. The FALSE is sent to the same function in the case you need combo representation to be updated from the variable.
The better choice might be to create your member of the type CComboBox. Then you don't even need to call this function, but only to read the combo value using GetWindowText(). The oposite direction goes just like in the answer 1.

I hope this answers your question.

Author

Commented:
thanks again, ekc.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.