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

本文探讨了COMBO框自动完成功能在使用过程中遇到的问题,并提供了一种规避此问题的方法。通过自定义函数SetAllComBoxText和GetAllComBoxText实现了对COMBO框内容的控制,确保了用户输入不会被自动覆盖。

 本来以为很简单,不过实现起来,发现不少问题,至今仍没有解决的问题就是为什么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版本

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值