unit ComboListBox;interfaceuses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls,ExtCtrls;type
  TComboListBox = class(TComboBox)
  private
    { Private declarations }
    AutoListbox:TListbox;
    mouseclick:boolean;
    procedure listboxclick(sender:TObject);
  protected
    { Protected declarations }
    procedure Change;override;
  public
    { Public declarations }  published
    { Published declarations }
    //property left stored true;
  end;procedure Register;implementationprocedure Register;
begin
  RegisterComponents('Standard', [TComboListBox]);
end;procedure TCombolistbox.listboxclick(sender:TObject);
begin
  text:=AutoListbox.items[AutoListbox.itemIndex];
  autolistbox.free;
  mouseclick:=true;
end;procedure TCombolistbox.Change;
var
  i:integer;
begin
  inherited;
  if not mouseclick then
  begin
    if not assigned(Autolistbox) then
    begin
      AutoListbox:=TListbox.create(self);
      AutoListbox.parent:=TWincontrol(self.Owner);
      Autolistbox.top:=top+height;
      Autolistbox.left:=left;
      AutoListbox.width:=Width;
      Autolistbox.height:=60;
      Autolistbox.OnClick:=listboxClick;
      mouseclick:=false;
    end;
    Autolistbox.items.clear;
    for i:=0 to self.items.count-1 do
    begin
    if pos(self.text,self.items[i])>0 then
      Autolistbox.Items.add(self.items[i]);
      //Autolistbox.Refresh;
    end;
    Autolistbox.sorted:=true;
  end;
end;end.
望高手们指点,谢谢。

解决方案 »

  1.   

    错误如下:当在combobox中的edit框中输入字符时,会弹出一个listbox,
    里面有候选项,当选择一个字符串时报错。
      

  2.   

    报错内容是什么?你在listbox里选择字符串后,是不是将该值赋给了combolistbox?那又会出发change事件
      

  3.   

    虽然又触发了Onchange事件,但是只会调用change方法中的inherited语句,并未执行其它代码。该控件单元编译时无错,但是,我在一个新的application的主窗体上加上一个combolistbox,编译执行后,报错:Access violation at address 00402E04 in module 'Project1.exe'.Read of address 00CD400.
      

  4.   

    to dht2003(海) :
      你有没有试过这个控件?
      

  5.   

    我Install了一下。没有出错,就是不太好使。
      

  6.   

    你在items里添加几个字符串,然后运行。在此控件的Edit框中输入字符,若出现listbox,选择其中一项试试。
      

  7.   

    我这没事儿。只是只能在窗体打开后执行一次。然后就不出不来ListBox了。你试试重写CM_CHANGED消息。