Autor Beitrag
Stefan-W
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 475

Win 7 SP1
D2005 PE
BeitragVerfasst: So 28.08.05 11:28 
Hi,

ich suche grad nach einer Möglichkeit ein Item in einer Listbox zu verschieben.

(zB. von der zweiten an die fünfte Position)

hat jemand eine Idee wie man das realisieren kann?

Schonmal vielen dank im Voraus

TSchau Stefan
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: So 28.08.05 11:46 
Hatte grade nix zu tun, und wollte das auch mal ausprobieren:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
var
  DragItem:integer;

{...}

procedure TForm1.ListBox1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var p:tpoint;
begin
  p.X:=x;
  p.Y:=y;
  // Aktuelles Item bestimmen und merken
  DragItem := Listbox1.ItemAtPos(p,true);
  // Drag&Drop Aktion starten
  with Sender as Tlistbox do
    begindrag(False);
end;

procedure TForm1.ListBox1DragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
var p:tpoint;
  AktItem:integer;
begin
  accept := True;

  // als Zusatz: Item in "Echtzeit verschieben"
  p.X:=x;
  p.Y:=y;
  AktItem := Listbox1.ItemAtPos(p,true);
  Listbox1.Items.Move(DragItem,AktItem);
  DragItem := AktItem;
end;

procedure TForm1.ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);
var p:tpoint;
  AktItem:integer;
begin
  // Drag&Drop Aktion beenden und Item vertauschen
  p.X:=x;
  p.Y:=y;
  AktItem := Listbox1.ItemAtPos(p,true);
  Listbox1.Items.Move(DragItem,AktItem);
end;

_________________
We are, we were and will not be.
Stefan-W Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 475

Win 7 SP1
D2005 PE
BeitragVerfasst: So 28.08.05 11:50 
:D Vielen Dank für die schnelle Antwort :!: :!:

ist genau das was ich wollte

noch ein schönes Wochneende
Tschau Stefan