您的位置:首页 > 其它

向combobox控件中添加元素

2016-01-15 16:36 267 查看
函数定义:
bool FillComboBox(CComboBox* pc, CStringList& slValues, bool bOnlyUniqueValues = false);
函数实现:
bool FillComboBox(CComboBox* pc, CStringList& slValues, bool bOnlyUniqueValues)
{
POSITION pos;
CString  s;

pc->ResetContent();
for (pos = slValues.GetHeadPosition(); pos != NULL;) {
s = slValues.GetNext(pos);
if (bOnlyUniqueValues) {
// String already in combobox
if (pc->FindStringExact(0, s) != CB_ERR) {
continue;
}
}
pc->AddString(s);
}

return true;
}


将字符串列表中的字符串加入combobox控件中,如:

FillComboBox(&m_combobox, strList);

其中m_combobox为combobox控件相关联的变量,strList为CStringList类型,里面保存的是要加入combobox控件中的字符串。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: