![]() |
Wieder einmal Drag & Drop
Hallo,
ein alt bekanntes Problem. Ich möchte mit einer FileListBox und einer ListBox Drag & Drop realisieren. Soweit funktioniert es auch. Leider wird beim ziehen und fallen lassen einer Datei, der gesamte Inhalt des Ordners abgelegt.
Delphi-Quellcode:
Könnte es sein, dass hier noch irgendwas fehlt?
procedure TForm1.FormCreate(Sender: TObject);
begin ListBox1.OnDragOver := ListBox1DragOver; Listbox1.Dragmode := dmAutomatic; ListBox1.MultiSelect := true; FileListbox1.Dragmode := dmAutomatic; FileListBox1.MultiSelect := true; end; procedure TForm1.ListBox1DragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean); begin accept := (Source is TFileListBox) and (sender<>Source); end; procedure TForm1.ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer); var i: Integer begin if Source is TFileListBox then begin i:=(Source as TFileListBox).ItemIndex; ListBox1.Items.Add((Source as TFileListBox).Items[i]); end; end; end. PS: Das Ziehen mehrerer Dateien gleichzeitig ist ein muß. |
Re: Wieder einmal Drag & Drop
Du musst natürlich dein i auch verwenden. Zum Beispiel so:
Delphi-Quellcode:
Und bei mehreren musst du halt eine Schleife über die Items in Source machen und über die Eigenschaft Selected abfragen, ob der Eintrag ausgewählt ist. Wenn ja. Der anderen Listbox hinzufügen.
ListBox1.Items.Add((Source as TFileListBox).Items[i];
|
Re: Wieder einmal Drag & Drop
Jetzt ist die Verwirrung komplett.
|
Re: Wieder einmal Drag & Drop
Zitat:
Delphi-Quellcode:
In der Hoffnung, dich nicht noch mehr zu verwirren ;)
for Dummy:=0 to (Source as TFileListBox).Items.Count-1 do
begin if (Source as TFileListBox).Items.Selected[Dummy] then ListBox1.Items.Add( Source as TFileListBox).Items[Dummy]); end; |
Re: Wieder einmal Drag & Drop
Danke, hat geklappt.
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:20 Uhr. |
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 by Thomas Breitkreuz