No i udało się dzięki koledze z netu , który mi pomógł.
Podziękowania dla Arkadiusza Pawlika
[email protected]
uses
Windows,Messages,commctrl,CommDlg ;
var
ListView1:Hwnd;
kolumna:LV_COLUMN;
wiersz :LV_ITEM;
obracanie:boolean;
sortowanie: array[0..21] of boolean;
function StrPas(const Str: PChar): string;
begin
Result := Str;
end;
procedure UpdatelParams;
var
i:longint;
begin
for i :=0 to ListView_GetItemCount(ListView1)-1 do
begin
wiersz.mask:=LVIF_PARAM;
wiersz.iItem:=i;
wiersz.iSubItem:=0;
wiersz.lParam:=wiersz.iItem;
ListView_SetItem(ListView1,wiersz);
end;
end;
function SortFunc(Item1,Item2,Column:{longint}lparam):integer stdCall;
var
K1,
K2 : array[0..255] of char;
S1,S2:string;
I1,
I2,i3 :integer;
begin
if obracanie then
begin
result:=1;
exit;
end;
ListView_GetItemText(listview1,integer(Item1),Column,@K1[0],SizeOf(K1));
ListView_GetItemText(listview1,integer(Item2),Column,@K2[0],SizeOf(K2));
S1:=StrPas(K1);
S2:=StrPas(K2);
case Column of
0 :
begin
end;
1,7,9,10,11,12,14 :
begin
i1:=pos(',',s1);
if i1=0 then s1:=s1+',0000';
i1:=pos(',',s1);
i3:=4-(length(s1)-i1);
for i2:=1 to i3 do s1:=s1+'0';
S1 := StringOfChar('0', 15) + S1;
i1:=pos(',',s2);
if i1=0 then s2:=s2+',0000';
i1:=pos(',',s2);
i3:=4-(length(s2)-i1);
for i2:=1 to i3 do s2:=s2+'0';
S2 := StringOfChar('0', 15) + S2;
S1 := Copy(S1, Length(S1) - 15, 16);
S2 := Copy(S2, Length(S2) - 15, 16);
end;
2,3,4,5,6,8,13,15,16,17,18,19 :
begin
end;
end;
if Column >= 0 then
begin
if S1 = S2 then Result := 0;
if S1 < S2 then Result := -1;
if S1 > S2 then Result := 1;
end;
end;
WM_NOTIFY:
begin
if PNMLVCustomDraw(LParam)^.nmcd.hdr.code=LVN_COLUMNCLICK then
begin
//jesli raz juz posortowalismy do drugi raz tylko obracamy liste
if not sortowanie[PNMListView(Lparam)^.iSubItem] then
begin
for i:=0 to 21 do sortowanie[i]:=false; //ilosc kolumn
sortowanie[PNMListView(Lparam)^.iSubItem]:=true;
obracanie:=false;
end
else
obracanie:=true;
UpdatelParams; //zaladowanie do LParam aktualnych wartosci
ListView_SortItems(listview1,pfnlvcompare(@Sortfunc),(PNMListView(Lparam)^.iSubItem));
UpdatelParams; //zaladowanie do LParam aktualnych wartosci
exit;
end;
end;