您的位置:首页 > 技术教程 > vc

实现ComboBox输入文字的自动完成
【字体: 整理日期:2008-10-31 11:21:19 打印本文】 【收藏此文

word lastkey ;

//---------------------------------------------------------------------------
void __fastcall tform1::combobox1change(tobject *sender)
{
string value = combobox1->text ;

// if the user tried to delete he must not want to change anything.
if (lastkey == \’\\b\’ || lastkey == vk_delete)
{
lastkey = 0 ;
return ;
}
lastkey = 0 ;
// 确保使用者没有在中间插入字符
if (combobox1->selstart != value.length ())
return ;

// 在下拉列表中寻找匹配项.
int index = sendmessage (combobox1->handle, cb_findstring, -1, (lparam) value.c_str ()) ;
if (index >= 0)
{
// 找到匹配项并显示.
combobox1->itemindex = index ;
string newtext = combobox1->text ;
sendmessage (combobox1->handle, cb_seteditsel, 0, makelparam (value.length (), -1)) ;
}
}
//---------------------------------------------------------------------------
void __fastcall tform1::combobox1keydown(tobject *sender, word &key,
tshiftstate shift)
{
// 按下的最后一个键值.
lastkey = key ;
}
//---------------------------------------------------------------------------



查询
关键词:
相关文章
标签Tags