1、定义控件变量
右键(或ctrl+W)打开 Class Wizard 对话框,选择member variables选项页,为控件增加变量。如控件ID为IDD_ComboxExamble,为其增加变量CComboBox类型变量m_cbExamble,即CComboBox m_cbExamble。
2.给控件添加数据项
方法一:在空间的properties(属性)的Data中添加。用ctrl+enter换行,enter确定
方法二:在代码中添加。
如:CString str;
m_cbExample.GetLBText( nIndex, str);
其中nIndex是选定项的位置序号。
5.给定字符串str,查找其位置。
(1)利用函数FindStringExact() 精确匹配。
如:int nIndex = m_cbExample.FindStringExact( nStart, str);
nStart指明从哪一行开始查找。如果查找成功,返回的是该项的位置;否则,返回CB_ERR。
(2)利用函数SelectString粗略查找。返回包含指定字符串str的项的位置,
如:int nIndex = m_cbExample.SelectString( nStartAfter, str);
6.删除控件中的Item
(1)利用函数DeleteString()删除指定位置处的Item,如:m_cbExample.DeleteString(nIndex);
(2)利用函数ResetContent(),清除所有项,如:m_cbExample.ResetContent();
7.利用函数SetCurSel显示控件中指定位置处的Item。如:m_cbExample.SetCurSel(nIndex); //显示第nIndex项