我现在创建了两个列表框组件ListBox1,ListBox2.我现在想实现这样的功能.
1)ListBox2里的数据是从数据库中取过来的
2)选择ListBox2的数据,双击它就增加到ListBox1里去了,或者通过按扭把选择的数据增加到Listbox1里去.
我想这应该是个很菜的问题,可对一个刚学Delphi的新人来说有点麻烦.我找了很多资料没有找到.
最好是祥细一点.谢谢先!

解决方案 »

  1.   

    procedure TForm1.ListBox2DblClick(Sender: TObject);
    begin
      if (ListBox2.ItemIndex > -1) and
        (ListBox1.Items.IndexOf(ListBox2.Items[ListBox2.ItemIndex]) = -1) then
      begin
        ListBox1.Items.Add(ListBox2.Items[ListBox2.ItemIndex]);
        ListBox2.Items.Delete(ListBox2.ItemIndex);
      end;
    end;
      

  2.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ExtCtrls, StdCtrls, DB, ADODB;type
      TForm1 = class(TForm)
        Table: TADOTable;
        ListBox1: TListBox;
        ListBox2: TListBox;
        procedure FormKeyPress(Sender: TObject; var Key: Char);
        procedure FormCreate(Sender: TObject);
        procedure ListBox2DblClick(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
    begin
      inherited;
      if key <> #13 then exit;
      key := #0;
      Perform(wm_nextdlgctl, 0, 0)
    end;procedure TForm1.FormCreate(Sender: TObject);
    beginwhile not table.Eof do
    begin
      listbox2.AddItem(table.fieldbyname('UserName').AsString ,listbox2);
      table.Next;end;
    end;
    procedure TForm1.ListBox2DblClick(Sender: TObject);
    begin
      listbox1.AddItem(listbox2.Items[listbox2.Itemindex],listbox1 );
    end;
    end.