专注于互联网--专注于架构

最新标签
网站地图
文章索引
Rss订阅

首页 »C 教程 » combobox:实现ComboBox输入文字的自动完成 »正文

combobox:实现ComboBox输入文字的自动完成

来源: 发布时间:星期四, 2008年9月25日 浏览:200次 评论:0
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 ;
}
//---------------------------------------------------------------------------
0

相关文章

读者评论

发表评论

  • 昵称:
  • 内容: