我希望实现Combox中联想输入的功能,combox的输入项目在数据库中保存;
当combox输入时,自动下拉,动态列出item项目,请给方法或者给可以这样实现的控件!
确实可行马上给分;比如:
combox.items.add('测试1');
combox.items.add('测试2');
combox.items.add('测试3');
combox.items.add('test1');
combox.items.add('test2');
当我在combox.text输入:测试
combox的item只列出:
combox.items.add('测试1');
combox.items.add('测试2');
combox.items.add('测试3');

解决方案 »

  1.   

    用个EDIT用来输入,然后按键触发cmb的DroppedDown属性(直接从数据库查询即可)
      

  2.   

    看你这要求,直接用edit跟listbox组合就好了
      

  3.   

    在Onkeyup事件中加入此代码,
    procedure TForm1.ComboBox1KeyUp(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    var
      vSql, vInput: string;
    begin
      vInput := ComboBox1.Text;
      vSql := 'select departName from vo_department where departName like ''%'+ vInput +'%''';
      Memo1.Lines.Add(vSql);
      with ADOQuery1 do
      begin
        Close;
        SQL.Clear;
        SQL.Add(vSql);
        Open;
        First;
        ComboBox1.Items.Clear;
        while not Eof do
        begin
          ComboBox1.Items.Add(fieldbyName('departname').AsString);
          Next;
        end;
      end;
      ComboBox1.AutoDropDown := True;
      ComboBox1.AutoComplete := True;
      ComboBox1.SelStart:=Length(vInput);
    end;
      

  4.   

    procedure TForm1.FormShow(Sender: TObject);
    var
       i:integer;
    begin
      ComboBox1.Items.Add('测试1');
      ComboBox1.Items.Add('测试2');
      ComboBox1.Items.Add('测试3');
      ComboBox1.Items.Add('测试4');
      ComboBox1.Items.Add('123');
      ComboBox1.Items.Add('456');
      ComboBox1.Items.Add('vag1');
      ComboBox1.Items.Add('vag');
      ComboBox1.Items.Add('vag2');
      ComboBox1.Items.Add('vag3');
      //把列表保存在TStringList里面
      for i:=0 to ComboBox1.Items.Count-1 do str.Add(ComboBox1.Items.Strings[i]);end;procedure TForm1.ComboBox1KeyUp(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    var
      i,count:Integer;
      text:String;
    begin
     
      text:=ComboBox1.Text;//保存输入的文本
      count:=Length(ComboBox1.Text);// 保存长度  ComboBox1.Clear; //清除列表  //加载新的列表
      for i:=0 to str.Count-1 do
      begin
        if LeftStr(str.Strings[i],count)=text then
          ComboBox1.Items.Add(str.Strings[i]);
      end;
      
      ComboBox1.AutoDropDown:=true;
      ComboBox1.AutoComplete:=true;
      ComboBox1.Text:=text;//复原输入的文本
      ComboBox1.SelStart:=count;
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
        str:=TStringList.Create;
    end;