CComBox关于 SelectString使用误区

  int SelectString(int nStartAfter,LPCTSTR lpszString);

这个nStarAafter=-1,表示整个列表
但是这个是字符串包含关系,模糊匹配

如果,CComBox中的字符串顺序是

【新楼层2】

【新楼层】

【主楼层】

 

如果当前已经是hi选择了【新楼层】,再次用SelectString(1, L"新楼层"); 是选择不到新楼层的

void CMFCApplication3Dlg::OnCbnSelchangeCombo2()
{
	int isel = m_combo.GetCurSel();
	if (isel < 0)
	{
		return;
	}
	CString strText = _T("");
	m_combo.GetLBText(isel, strText);
	strText.Trim();


	m_combo.ResetContent();
	int idx=0;
	m_combo.InsertString(idx++, L"新建层2");
	m_combo.InsertString(idx++, L"新建层");
	m_combo.InsertString(idx++, L"主楼层");


	m_combo.SelectString(-1, strText); //是模糊匹配,这句话是错误的,需要for循环查找对应字符串

}

  


name每次点选择【新楼层】的时候,会从0开始查找,查到【新楼层2】的时候,不再查找 【新楼层】

所以如果CComBox中有字符串重合部分的,不要用这个函数

posted @ 2022-12-14 23:06  曦花  阅读(96)  评论(0编辑  收藏  举报