本来以为很简单,不过实现起来,发现不少问题,至今仍没有解决的问题就是为什么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版本
本文探讨了COMBO框自动完成功能在使用过程中遇到的问题,并提供了一种规避此问题的方法。通过自定义函数SetAllComBoxText和GetAllComBoxText实现了对COMBO框内容的控制,确保了用户输入不会被自动覆盖。
492

被折叠的 条评论
为什么被折叠?



