在onchange事件中
if combobox.items.indexof('xxx') <> -1 then
  combobox.itemindex := combobox.items.indexof('xxx') 

解决方案 »

  1.   

    这个极简易
    发过来我帮助你搞定
    [email protected]
      

  2.   

    是不是用中文版delphi,我现在用的是delphi6(english)
      

  3.   

    我试了试,输入中文可以。是不是你的开始位置,结束位置,等数值有错,比方半个汉字问题。
    BCB语法,请参考。
    (private : WORD key;)
    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 ;
      // Make sure the user is not typing something in the middle or else
      // proceeding will make the caret jump.
      if (ComboBox1->SelStart != value.Length ())
        return ;  // Find the item matching text in the dropdown.
      int index = SendMessage (ComboBox1->Handle, CB_FINDSTRING, -1, (LPARAM) value.c_str ()) ;
      if (index >= 0)
      {
        // There was a match so now set up the selected text.
        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)
    {
      // Save the last key pressed.
      lastkey = Key ;
    }
      

  4.   

    改正一下:(private : WORD lastkey;)
      

  5.   

    请问
    在delphi中两个sendmessage应如何设,CB_FINDSTRING,CB_SETEDITSEL是不是在 window.pas中有 是&H14c 和 &H14F吗?下列代码应如何改正? procedure TForm1.ComboBox1Change(Sender: TObject);
    var value:string;
    index:integer;
    newtext:string;
    str:string;
    begin value:=combobox1.Text;
      if combobox1.SelStart<>length(value) then
      exit;
      str:=copy(combobox1.Text,0,combobox1.SelStart);
      {if combobox1.items.indexof('''+combobox1.text+''') <> -1 then
      combobox1.itemindex := combobox1.items.indexof('''+combobox1.text+''');}
    index:=SendMessage (ComboBox1.Handle, CB_FINDSTRING , -1, str.asstring ) ;
     if index>0 then
     ComboBox1.ItemIndex := index ;
         newtext := ComboBox1.Text ;
        SendMessage (ComboBox1.handle,CB_SETEDITSEL , 0, MAKELPARAM (LENGTH(VALUE),-1)) ;end;