procedure TForm1.FormCreate(Sender: TObject);
begin
 with adoquery1 do
  begin
    close;
    sql.Clear;
    sql.Add('select medid,medname,mindose_value from yk_medzd');
    open;
    while not eof do
     begin
      combobox1.Items.Add(fieldbyname('medname').AsString+' '+fieldbyname('mindose_value').AsString);
      next;
     end;
  end;
end;

解决方案 »

  1.   

    procedure TForm1.ComboBox1Change(Sender: TObject);
    begin
    SENDMESSAGE(COMBOBOX1.HANDLE,CB_SHOWDROPDOWN,INTEGER(TRUE),0);
    COMBOBOX1.
     with adoquery1 do
      begin
        close;
        sql.Clear;
        sql.Add('select medid,medname,mindose_value,pym from yk_medzd where pym like '''+ComboBox1.text+'%'' order by medname desc');
        open;
        if recordcount<>0 then combobox1.Items.Clear;
        while not eof do
         begin
          combobox1.Items.Add(fieldbyname('medname').AsString+' '+fieldbyname('mindose_value').AsString);
          //combobox1.Text:= fieldbyname('medname').AsString+' '+fieldbyname('mindose_value').AsString;
          next;
         end;
         ///combobox1.Text:= combobox1.Items.CommaText
      end;
      

  2.   

    可以考虑初始时复制一份排序过的ComboBox1.Items的副本到另一个字符串表(如Strings2)中,
    以后可以直接用二分法从(Strings2)中找到包含ComboBox1.Text的首位及末位,将首位及末位间所有字符串复制给ComboBox1.Items。
      

  3.   

    /******************************************************************************/
    /*功能ID    :CheckCb                                                         */
    /*功能描述  :ComboBox/DBComboBox控件输入限制及自动搜索功能                   */
    /*调用参数  :TComboBox* Sender:需要进行输入限制与自动搜索的ComboBox/DBComboBox*/
    /*返回值    :                                                                */
    /*调用方法  :1.在Form的 .cpp 中定义:     extern Word  LastKey;               */
    /*            2.在ComboBox的KeyDown时记下最后的按键: LastKey = Key;           */
    /*            3.在ComboBox的OnChange事件中调用:      CheckCb(cbSendType);     */
    /******************************************************************************/
    void CheckCb(TCustomComboBox* Sender)
    {
        AnsiString strOld = "";
        int iIndex = 0;
        
        if ((String(Sender->ClassName())) == "TComboBox")
            strOld = ((TComboBox*)Sender)->Text;
        if ((String(Sender->ClassName())) == "TDBComboBox")
            strOld = ((TDBComboBox*)Sender)->Text;    if ((LastKey == VK_BACK)||(LastKey == VK_RETURN)||(LastKey == VK_TAB))
            LastKey = '\0x00';
        else
        {
            iIndex = SendMessage(Sender->Handle,CB_FINDSTRING,-1,LPARAM(strOld.c_str()));
            if (iIndex >= 0)
            {
                Sender->ItemIndex = iIndex;
                SendMessage(Sender->Handle,CB_SETEDITSEL,0,MAKELPARAM(strOld.Length(),WORD(-1)));
            }
            else
            {
                keybd_event(VK_BACK,MapVirtualKey(VK_BACK,0),0,0);
                keybd_event(VK_BACK,MapVirtualKey(VK_BACK,0),KEYEVENTF_KEYUP,0);
                Beep();
            }
        }
    }
      

  4.   

    上面是经我改造增强的,并以C++Builder写的,
    下面是一篇原文:            搜索最佳匹配的“智能复选框
                // 定义变量            LastKeyPressed: Word;             procedure TForm1.ComboBox1KeyDown(Sender: TObject; var Key: Word; 
                  Shift: TShiftState); 
                begin 
                  LastKeyPressed := Key;  // 保存上一个你按的键
                end;             procedure TForm1.ComboBox1Change(Sender: TObject); 
                Var 
                  ComboText : String; 
                  NewComboText : String; 
                  matchindex     : integer; 
                begin 
                  ComboText := ComboBox1.Text; 
                  // 使用户能删除文本; 
                  if (LastKeyPressed = VK_DELETE) OR (LastKeyPressed = 8 )  then 
                begin 
                    LastKeyPressed := 0; 
                  end 
                  else begin 
                    if ComboBox1.SelStart <> length (ComboText) then // 确定用户此时刚开始打字
                  // 不做任何事,因为这可以让用户在文本中间任意打字
                    else begin 
                      // 寻找匹配 
                      matchindex  := sendmessage ( ComboBox1.Handle, CB_FINDSTRING , 
                -1, 
                                             LPARAM(ComboText) )  
                      if matchindex >= 0 then begin 
                        ComboBox1.ItemIndex := matchindex  
                        NewComboText        := ComboBox1.Text; 
                        // 选择文本的其余部分: 
                        sendmessage ( ComboBox1.Handle, CB_SETEDITSEL , 0, 
                                             MAKELPARAM(length(ComboText) , word(-1) 
                )); 
                      end; 
                    end; 
                end;
      

  5.   

    谢谢happyzsl(学习) 
    大家继续呀,我急用啊
      

  6.   

    >>下拉框的自动检索
    把AutoComplete属性设为true不就行了
      

  7.   

    不知道你要实现什么功能?
    看你的程序好像用ComboBox不大合适,可以考虑换别的控件来实现。
    比如:edit+dagrid
      

  8.   

    我刚刚一个完成类似的功能的DLL,呵呵
    {输入拼音简码,检索相应的名称}
    {}
    楼主要的话给我分吧,哈哈
    并留下Email