Einzelnen Beitrag anzeigen

Hansa

Registriert seit: 9. Jun 2002
Ort: Saarland
7.554 Beiträge
 
Delphi 8 Professional
 
#18

Re: Items einer ListBox mittels DragDrop verschieben?

  Alt 28. Mai 2009, 22:11
Mir kommt das zu kompliziert vor, was hier fabriziert wird.

Prinzipiell geht das jedenfalls so :

Delphi-Quellcode:
unit draguni;

interface

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

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    ListBox2: TListBox;
    procedure ListBox1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);
    procedure ListBox1DragOver(Sender, Source: TObject; X, Y: Integer;
      State: TDragState; var Accept: Boolean);
    procedure ListBox2DragOver(Sender, Source: TObject; X, Y: Integer;
      State: TDragState; var Accept: Boolean);
    procedure ListBox2DragDrop(Sender, Source: TObject; X, Y: Integer);
    procedure ListBox2MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ListBox1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if button = mbLeft then with Sender as TListBox do begin
    if ItemAtPos (Point (x,y),true) >= 0 then
      BeginDrag (false);
  end;
end;

procedure TForm1.ListBox2MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if button = mbLeft then with Sender as TListBox do begin
    if ItemAtPos (Point (x,y),true) >= 0 then
      BeginDrag (false);
  end;
end;

procedure TForm1.ListBox1DragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
begin
  Accept := Source is TListBox;
end;

procedure TForm1.ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
  if Source is TListBox then with ListBox1 do begin
    Text := ListBox2.Items[ListBox2.ItemIndex];
    ListBox1.AddItem(Text,source);
    ListBox2.Items.Delete (ListBox1.ItemIndex);
  end;
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);
begin
  if Source is TListBox then with ListBox2 do begin
    Text := ListBox1.Items[ListBox1.ItemIndex];
    listbox2.AddItem(Text,source);
    ListBox1.Items.Delete (ListBox2.ItemIndex);
  end;
end;

end.
MultiSelect ist da zwar nicht drin, aber man kann die Items hin und her schieben. Aber, was heißt "parallel verschieben" ?
Gruß
Hansa
  Mit Zitat antworten Zitat