Autor Beitrag
redbird
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 38

Win XP, Vista Business (64bit), Win 7 Prof. (64bit)
Delphi 7, Java, PHP
BeitragVerfasst: Mo 27.03.06 20:43 
Moin,
ich sortiere eine Listview im report Stil nach bestimmten Kriterien. Bspw. sollen nur Zeile 1 und 2 in einer Listview sortiert werden, die anderen sollten so bleiben wie sie sind.
Wie lassen sich nur bestimmte Zeilen sortieren, bzw. wie formuliere ich die Bedingung innerhalb eines Oncompare-Ereignisses?

Danke,
Gruß
redbird
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: Mo 27.03.06 21:57 
Hallo,

mit dem Ereignis OnCompare wirst Du es IMHO nicht erreichen können.

Damit geht es:
Die Prozedur vergleicht die Caption, i und j ist der Index der Zeilen.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
procedure Sort2Row(LV: TListView;i,j: Integer);
var aTempItem : TListItem;
begin
  with LV do
    begin
    if Items[i].Caption > Items[j].Caption then
      begin
      Items.BeginUpdate;
      try
        aTempItem := TListItem.Create(Items);
        aTempItem.Assign(Items.Item[i]);
        Items.Item[i].Assign(Items.Item[j]);
        Items.Item[j].Assign(aTempItem);
        aTempItem.Free;
      finally
        Items.EndUpdate
      end;
      end;
   end;
end;
Soll nicht nach der Caption sortiert werden kannst Du es ja entsprechend umschreiben.

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
redbird Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 38

Win XP, Vista Business (64bit), Win 7 Prof. (64bit)
Delphi 7, Java, PHP
BeitragVerfasst: Sa 17.06.06 17:49 
Danke, hat sich nun erledigt.