想单击一次“添加”按钮就在comboBox里添加一个Items,并在text中显示出来,
应该怎么实现?用哪个属性?对这个组件我不熟悉,希望各位提示一下。

解决方案 »

  1.   

    combobox1.items.add();combobox1.index:=combobox1.items.count;
      

  2.   

    procedure TForm1.Button1Click(Sender: TObject);
    begin
    combobox1.Items.Add(edit1.Text);
    ComboBox1.ItemIndex:=ComboBox1.Items.Count-1;
    end;
      

  3.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        cbb1: TComboBox;
        Button1: TButton;
        procedure FormShow(Sender: TObject);
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        i: integer;
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormShow(Sender: TObject);
    begin
      i:=0;
      cbb1.Text:=IntToStr(i);
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      Inc(i);
      cbb1.Items.Add(IntToStr(i));
      cbb1.Text:=IntToStr(i);
    end;end.
      

  4.   

    procedure TForm1.Button1Click(Sender: TObject); 
    begin
     ComboBox1.Items.Add(edit2.Text); {添加edit2的内容到ComboBox1}
     Edit1.Text:=ComboBox1.Items.Strings[ComboBox1.Items.Count-1]; {显示添加的内容(最后一项)到Edit1}
    end;