- This topic has 1 reply, 1 voice, and was last updated 16 years ago by BattleStar-Galactica.
-
AuthorPosts
-
June 9, 2007 at 8:26 am #191196BattleStar-GalacticaMember
You have to read my previous post to able read this one. it will be quite short for this tuto.
1) start vc++6 and name it ComboBox
2) drag a comboxbox and a button to your form, see image 1we need to declare a variable type CComboBox, Do you remember where to declare a global variable for our app; for this project click on FileView and double click on ComboBoxDlg.h. scroll down right after DECLARE_MESSAGE_MAP(), enter the code bellow
public: CComboBox m_MyComboBox;
see image 2
we need to attach our variable m_MyComboBox with our ComboBox that we added to our form(Dialog app). How to do that, follow step 3
3) double click on ComboBoxDlg.ccp, scroll down you will see a procedure call something like this
void CComboBoxDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CComboBoxDlg) // NOTE: the ClassWizard will add DDX and DDV calls here //}}AFX_DATA_MAP }
in this procedure we will attach our m_MyComboBox with our ComBobox, right after the line //}}AFX_DATA_MAP, add follow code
DDX_Control(pDX,IDC_COMBO1,m_MyComboBox);
see image 3
now we’re going to add some value to that combobox
4) on button click procedure
– to add some value to this combobox, simply do this >>CString str="some item"; m_MyComboBox.AddString(str);
– get some current selected item
CString str; int idx = m_MyComboBox.GetCurSel(); m_MyComboBox.GetLBText( idx, str );
str will content the current item selected
– and to delete current item selected
int idx = m_MyComboBox.GetCurSel(); m_MyComboBox.DeleteString(idx);
you’re done 😀
I attach a demo project for this tuto, in the demo project I show you also implement CEdit class to deal with edit control that I didn’t show in previous post.June 9, 2007 at 8:28 am #191197BattleStar-GalacticaMemberxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-
AuthorPosts
Related
- You must be logged in to reply to this topic.