Delphi-PRAXiS
Seite 2 von 3     12 3      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi Items einer ListBox mittels DragDrop verschieben? (https://www.delphipraxis.net/134781-items-einer-listbox-mittels-dragdrop-verschieben.html)

oki 28. Mai 2009 20:55

Re: Items einer ListBox mittels DragDrop verschieben?
 
ah, sorry, hab das whith sender as übersehen.

Ähm, da fällt mir auf, muss der ItemIndex nicht von Source gelesen werden? Ist wohl schon zu spät für mich.

Gruß

AlexII 28. Mai 2009 20:56

Re: Items einer ListBox mittels DragDrop verschieben?
 
Und hast du Idee wie man die Items der ListBox2 parallel verschiebt?

oki 28. Mai 2009 20:58

Re: Items einer ListBox mittels DragDrop verschieben?
 
welche ListBox2?

Wenn die genauso aussieht, einfach die Items aus 1 nach 2 mittels Assign kopieren.

Gruß

AlexII 28. Mai 2009 21:00

Re: Items einer ListBox mittels DragDrop verschieben?
 
Hab das so gemacht:

Delphi-Quellcode:
procedure TForm1.ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);
var TargetIndex : Integer;
begin
  if (Sender is TListBox) and (Source is TListBox) then
  begin
    with Sender as TListBox do
    begin
      TargetIndex := ItemAtPos(Point(X, Y), True);
      if (ItemIndex > -1) and (TargetIndex > -1) then
      begin
      Items.Move(ItemIndex, TargetIndex);
      ListBox2.Items.Move(ListBox2.ItemIndex, TargetIndex);       <-----
      end;
    end;
  end;
end;
Ist das ok was meinst du?

oki 28. Mai 2009 21:04

Re: Items einer ListBox mittels DragDrop verschieben?
 
Delphi-Quellcode:
procedure TForm1.ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);
var TargetIndex : Integer;
begin
  if (Sender is TListBox) and (Source is TListBox) then
  begin
    with Sender as TListBox do
    begin
      TargetIndex := ItemAtPos(Point(X, Y), True);
      if (ItemIndex > -1) and (ItemIndex > -1) then
      begin
        Items.Move(ItemIndex, TargetIndex);
      end;
    end;
    ListBox2.Items.Assign(ListBox1.Items);
  end;
end;
Ich tu mich heute aber schwer :mrgreen:

AlexII 28. Mai 2009 21:07

Re: Items einer ListBox mittels DragDrop verschieben?
 
Danke dir :thumb:
Kannst du das vllt noch in dem Code #6 ändern? Der gefällt mir besser, für das Auge verschiebt er besser.

oki 28. Mai 2009 21:10

Re: Items einer ListBox mittels DragDrop verschieben?
 
Oh man eh. Teste erst mal obs klappt. Bin heut nicht mehr so gut drauf.

Hansa 28. Mai 2009 21:11

Re: Items einer ListBox mittels DragDrop verschieben?
 
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" ?

AlexII 28. Mai 2009 21:13

Re: Items einer ListBox mittels DragDrop verschieben?
 
Zitat:

Zitat von oki
Oh man eh. Teste erst mal obs klappt. Bin heut nicht mehr so gut drauf.

Mein Methode klappt, aber ich würde das in dem Code #6 haben. Na gut, hab schon eine Lösung. :-D

oki 28. Mai 2009 21:19

Re: Items einer ListBox mittels DragDrop verschieben?
 
Dein Code ist auch ok. Das Assign ist auch nur zu empfehlen, wenn die Anzahl der Items nicht zu hoch ist. Das gleiche gilt für deinen Code in #6. Warum soll denn alles schon beim DragOver verschoben werden? Das ist bei vielen Items sicher auch mächtig Performance lastig.

Gruß


Alle Zeitangaben in WEZ +1. Es ist jetzt 05:56 Uhr.
Seite 2 von 3     12 3      

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz