Board index » delphi » Drag'n'Drop listbox in Delphi 6

Drag'n'Drop listbox in Delphi 6

Hi,

Does anybody know about a good and easy-to-use D6-component, that enables
you to use drag-drop between two listboxes.

Thanks in advance!

--
Emil

 

Re:Drag'n'Drop listbox in Delphi 6


On Sun, 4 Nov 2001 21:21:35 +0100, "Emil Rossing"

Quote
<e...@NOSPAMrossing.org> wrote:
>Hi,

>Does anybody know about a good and easy-to-use D6-component, that enables
>you to use drag-drop between two listboxes.

How about the ListBox control ?

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    ListBox2: TListBox;
    Button1: TButton;
    procedure ListBox2DragDrop(Sender, Source: TObject; X, Y:
Integer);
    procedure Button1Click(Sender: TObject);
    procedure ListBox2EndDrag(Sender, Target: TObject; X, Y: Integer);
    procedure ListBox2DragOver(Sender, Source: TObject; X, Y: Integer;
      State: TDragState; var Accept: Boolean);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
Var
  L9:Integer;
begin
  For L9 := 1 To 20 Do
      ListBox1.Items.Add( IntToStr(L9) ) ;
  ListBox1.DragMode := dmAutomatic ;
end;

procedure TForm1.ListBox2EndDrag(Sender, Target: TObject; X, Y:
Integer);
begin
   //
end;
procedure TForm1.ListBox2DragOver(Sender, Source: TObject; X, Y:
Integer;
  State: TDragState; var Accept: Boolean);
begin
  Accept := Source Is TListbox ;
end;

procedure TForm1.ListBox2DragDrop(Sender, Source: TObject; X, Y:
Integer);
  Var
  S : String ;
  I : Integer ;
begin
  If Not (Source Is TListBox ) Then Exit ;

  I := Listbox1.ItemIndex ;
  S := ListBox1.Items.Strings[I] ;
  ListBox2.Items.Add( S ) ;

end;

end.

Other Threads