函数定义:
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控件中的字符串。

相关文章:

  • 2022-12-23
  • 2021-12-29
  • 2021-09-21
  • 2022-12-23
  • 2021-09-17
  • 2021-11-27
  • 2021-11-19
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-16
  • 2022-12-23
  • 2022-01-25
  • 2022-01-20
相关资源
相似解决方案