combox的二次查询功能,既动态更改combox里面的内容

来源:互联网 发布:淘宝二维码怎么生成 编辑:程序博客网 时间:2024/05/21 11:07

 本来以为很简单,不过实现起来,发现不少问题,至今仍没有解决的问题就是为什么combox要有自动完成功能,比如combox下的listbox有如下几条数据:ds-sdfk;dgs-dfjl中国人98;但是啦开发;dskgadfka,用户一旦输入ds,然后再单击一下combox的编辑框或者调用showdropdown函数,或者单击到其他控件上去,combox便会自动把ds-sdfk填充到combox的编辑框去,这样就影响了动态提示符合条件项目的功能!

后来虽然没有彻底解决这个问题,但想了个好办法规避这种现象!

具体代码:

void SetAllComBoxText(CComboBox* mycombox,const CStringvect& mystrvect)
{
CString str;
int ncount=mystrvect.size();

mycombox->GetWindowText(str);
mycombox->ResetContent();
mycombox->SetWindowText(str);
mycombox->ShowDropDown(TRUE);
mycombox->SetEditSel(lstrlen(str),-1);
for(CStringvect::const_iterator it=mystrvect.begin();it!=mystrvect.end();it++)
{
mycombox->AddString((*it));
}

}

void GetAllComBoxText(CComboBox* mycombox,CStringvect& mystrvect)
{
mystrvect.clear();
CString str;
int ncount=mycombox->GetCount();
for(int i=0;i<ncount;i++)
{
mycombox->GetLBText(i,str);
mystrvect.push_back(str);
}


}
void GetFindComBoxText(LPCTSTR findstr,CStringvect& findstrvect,const CStringvect& mystrvect)
{
findstrvect.clear();

for(CStringvect::const_iterator it=mystrvect.begin();it!=mystrvect.end();it++)
{
if(strnicmp(findstr,(*it),strlen(findstr))==0)
{
//ATLTRACE("查找到了");
findstrvect.push_back((*it));
}
//ATLTRACE("查找%s %s/n",findstr,(*it));
}


}

详细代码可以到

http://www.cfxy.net/dispbbs.asp?boardid=46&id=2236

或者

http://www.codeproject.com/KB/combobox/CFComboBox.aspx

下载demo版本