Sortowanie listview

0

Jak zrobić żeby w listview o ViewStyle:= vsRaport po naciśnięciu kolumny 1 sortuje alfabetycznie według itemów z tej kolumny potem po naciśnięciu na kolumnę drugą sortuje według subitemów w tej kolumnie itd. --Pozdrawiam eSka :-)

0

W Object Inspektor jest takie cos jak SortStyle :) Listview1.sortstyle := itp.

Jezxeli nie sort style to sie pomylilem ;) {browar}

0

Przyklad moze przydlugawy, ale nie mam za bardzo czasu na jego przycinanie:
W tym programiku o ile dobrze pamietam obslugiwalem klikniecia na wsie kolumny (a bylo ich chyba z 12) o roznych typach danych (Date,Float,String itp) , przy czym na kolumnie byl umieszczony rozniez glyph (asc,desc) i oczywiscie mozna bylo sortowac
rosnaco i malejaco. Chcialem Ci to wyslac przez GG ale sie nie odzywasz .... coz twoj wybor :)

procedure TForm1.ListView1Compare(Sender: TObject; Item1, Item2: TListItem;
Data: Integer; var Compare: Integer);
var ts : Word;
d1,d2 : string;
l1,l2 : longInt;
r1,r2 : Real;
dt1,dt2 : TdateTime;
begin
if what_sort = 0 then
begin
d1 := item1.Caption;
d2 := item2.Caption;
end else
begin
d1 := Item1.SubItems[what_sort-1];
d2 := item2.SubItems[what_sort-1];
end;
if d1=d2 then begin Compare := 0;Exit;end;
ts := what_sort;
if (ts&gt0) and (cfg.pk=False) then ts := ts+1;
{jesli jest kod sprzedawcy to pomin}

case ts of
0 : begin
l1 := StrToInt(d1);
l2 := StrToInt(d2);
if l1&ltl2 then Compare := -1 else Compare := 1;
end;
1 : if d1&ltd2 then Compare := -1 else Compare := 1;
2 : if d1&ltd2 then Compare := -1 else Compare := 1;
3 : if d1&ltd2 then Compare := -1 else Compare := 1;
4 : if d1&ltd2 then Compare := -1 else Compare := 1;
5 : begin
dt1 := StrToDate(d1);
dt2 := StrToDate(d2);
if dt1&ltdt2 then Compare := -1 else Compare := 1;
end;
6 : begin
if d1='-' then dt1 := 0 else dt1 := StrToDate(d1);
if d2='-' then dt2 := 0 else dt2 := StrToDate(d2);
if dt1&ltdt2 then Compare := -1 else Compare := 1;
end;

     7 : begin
          if d1='-' then r1 := 0 else r1 := StrToFloat(d1);
          if d2='-' then r2 := 0 else r2 := StrToFloat(d2);
          if r1&ltr2 then Compare := -1 else Compare := 1;
         end;
     8 : if d1&ltd2 then Compare := -1 else Compare := 1;
     9 : if d1&ltd2 then Compare := -1 else Compare := 1;
    10 : begin
          if Length(d1)&lt8 then l1 := 0 else
          begin
           Delete(d1,1,7);
           l1 := StrToInt(d1);
          end;
          if Length(d2)&lt8 then l2 := 0 else
          begin
           Delete(d2,1,7);
           l2 := StrToInt(d2);
          end;
          if l1&ltl2 then Compare := -1 else Compare := 1;
         end;
     11 : begin
          if d1='-' then dt1 := 0 else dt1 := StrToDate(d1);
          if d2='-' then dt2 := 0 else dt2 := StrToDate(d2);
          if dt1&ltdt2 then Compare := -1 else Compare := 1;
         end;

end;

if how_sort=True then
begin if Compare=-1 then Compare := 1 else Compare := -1;end;
end;

procedure TForm1.ListView1ColumnClick(Sender: TObject;
Column: TListColumn);
var l,k : ShortInt;
begin
l := -1;
for k:=0 to Listview1.Columns.Count-1 do
if Listview1.Columns[k].Imageindex&lt&gt-1 then l := k;
if l=-1 then how_sort := False else how_sort := not how_sort;
what_sort := Column.Index;
if l&lt&gt-1 then
begin
Listview1.Columns[l].Imageindex:=-1;
if l&lt&gtwhat_sort then Listview1.Columns[l].Width := Listview1.Columns[l].Width-30;
end;
Column.ImageIndex := IndexObrazu[how_sort];
if l&lt&gtwhat_sort then Column.Width := Column.Width+30;
ListView1.AlphaSort;
end;

0

Ach ... jeszcze jedno - osoby "lubiace" licytowac czyje roziwazanie jest lepsze prosze o wstrzymanie - ten kod pisalem ladnych pare lat temu - wiec moze byc lekko pokaleczony :)

0

dzieki :) {browar} --Pozdrawiam eSka :-)

0

Fojcik napisał:
Ach ... jeszcze jedno - osoby \"lubiace\" licytowac czyje roziwazanie jest lepsze prosze o wstrzymanie - ten kod pisalem ladnych pare lat temu - wiec moze byc lekko pokaleczony :)

Wstrzymuje sie - bo to pewnie do mnie :-) :-) :-) --Pawel

Delphi6

0

Sorry Fojcik że się nie odezywałem ale byłem na dworze a komputera nie wyłączam bo po co, raczej ja nie siedzę przy kompie a tylko przychodzę coś tam postukam w klawiere i dalej gdzieś gonię--Pozdrawiam eSka :-)

1 użytkowników online, w tym zalogowanych: 0, gości: 1