AutoCAD 3DMAX C语言 Pro/E UG JAVA编程 PHP编程 Maya动画 Matlab应用 Android
Photoshop Word Excel flash VB编程 VC编程 Coreldraw SolidWorks A Designer Unity3D
 首页 > C++

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

51自学网 http://www.51zixue.net
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 ;
}
//---------------------------------------------------------------------------

 

 

 
上一篇:创建一个带有CheckBox的TreeView  下一篇:ListBox编程两例