当前位置:首页 >> 编程开发 >> Visual C++ >> 内容

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

时间:2009/11/20 作者:平凡之路 来源:xuhantao.com 浏览:

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相关评论
发表我的评论
  • 大名:
  • 内容:
  • 徐汉涛(www.xuhantao.com) © 2024 版权所有 All Rights Reserved.
  • 部分内容来自网络,如有侵权请联系站长尽快处理 站长QQ:965898558(广告及站内业务受理) 网站备案号:蒙ICP备15000590号-1