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 ;
}
//---------------------------------------------------------------------------