InsertString(int nIndex,LPCTSTR lpszString);
Example
CString strIns; int nItems = m_pComboBox->GetCount(); for (int i = 0; i < nItems; i++) { strIns.Format(_T("item string %c"), (char)('A'+i)); m_pComboBox->InsertString(2*i, strIns); } |
AddString(LPCTSTR lpszString);
Example
CString str; for (int i = 0; i < 20; i++) { str.Format(_T("item string %d"), i); m_pComboBox->AddString(str); } |
在列表的指定位置插入一项,可以使用成员函数InsertString和AddString
AddString()函数有一个参数,
该参数为要添加的以null结尾的字符串;
InsertString()函数有两个参数,
第一个参数为索引号,设定为-1时,项目条被插入到列表的末尾;
第二个参数与AddString 函数的唯一参数相同,为代表项目条中内容的字符串
使用InsertString时 ,第一个参数设定为-1时,列表中的项目条的排列顺序严格按照源代码中语句的顺序排列;
使用AddString时,列表中的项目条的顺序则按照英文字典序由上而下排列,如果想要按照添加顺序排列,需要在资源里的属性里把 Sort 属性改为False。