Autor Beitrag
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Di 13.02.07 21:31 
Habe bei TListView keine Methode gefunden, zwei Einträge zu vertauschen.
So gibt es z.B. bei TListbox Exchange.
Muss ich sowas selber implementieren oder habe ich etwas übersehen?

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Mi 14.02.07 00:47 
Hallo,

da gibt es keine Methode.
Änder doch den Code in dem Beitrag in der Library entsprechend:
ListView-Item nach oben oder unten verschieben

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Mi 14.02.07 11:49 
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:
//Written by Lannes  ( http://www.delphi-library.de/topic_+ListViewItem+nach+oben+oder+unten+verschieben_50284.html )
procedure MoveLVItem(LV: TListView; Direction: TSearchDirection);
var aItem, NextItem,TmpItem : TListItem;
begin
  with LV do
  begin
   if IsEditing or not Assigned(ItemFocused) then
      exit;//raus wenn Item editiert wird oder kein Item selektiert ist
    aItem := ItemFocused;
    case Direction of
      sdAbove : if aItem.Index = 0 then
                  exit;//Erstes Item ist markiert > raus
      sdBelow : if aItem.Index = Items.Count-1 then
                  exit;//Letztes Item ist markiert > raus
    end;
    NextItem := GetNextItem(aItem,Direction,[isNone]);
    Items.BeginUpdate;
    try
      TmpItem := TListItem.Create(Items);
      TmpItem.Assign(NextItem);
      NextItem.Assign(aItem);
      aItem.Assign(TmpItem);
      aItem.Selected := NextItem.Selected;
      TmpItem.Free;
      NextItem.MakeVisible(True);
      ItemFocused := NextItem;
      Selected := NextItem;
    finally
      Items.EndUpdate;
    end;
  end;
end;

//Aufruf:
procedure Tform_clmanager.btn_att_upClick(Sender: TObject);
begin
  MoveLVItem(listview_att,sdAbove);
end;

Aber es funktioniert nicht. :gruebel: Es passiert einfach nichts. (Ja, ich habe ein Item markiert. ;) )

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Mi 14.02.07 14:17 
Hallo,

setz doch mal einen Haltepunkt in Zeile 7, dann weiter mit F7.
In welcher Zeile steigt er aus, in Zeile 8,12 oder 14?

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Mi 14.02.07 14:24 
In Zeile 8 :shock:
Es ist garantiert eines markiert. Und was das mit IsEditing auf sich hat, kann ich nicht sagen.

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Mi 14.02.07 18:01 
Hallo,

zu IsEditing, schau mal den Kommentar im Code
ausblenden Delphi-Quelltext
1:
2:
   if IsEditing or not Assigned(ItemFocused) then  
      exit;//raus wenn Item editiert wird oder kein Item selektiert ist
wenn der InplaceEditor der ListView aktiv ist, kann es Probleme mit dem Verschieben von Items geben.

Setz mal vorm Funktionsaufruf den Focus auf die ListView:
ausblenden Delphi-Quelltext
1:
2:
listview_att.Setfocus;
MoveLVItem(listview_att,sdAbove);

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )