어디서 문제가 있나요?
아님면 ListView 오브젝트에서 뭔 설정을 해야 하나요?
OwnerData=True 하면 정렬 않되나요?
문제가 뭔지 알려주세요?
procedure TForm1.ListView1ColumnClick(Sender: TObject;
Column: TListColumn);
function CompareProc(lParam1, lParam2 : TListItem; lParamSort: Integer): Integer stdcall;
var
ix: integer;
begin
if bAssending then // Assending Sort
if nColumnToSort = 0 then
Result := CompareText(lParam1.Caption, lParam2.Caption)
else begin
ix := nColumnToSort - 1;
Result := CompareText(lParam1.SubItems[ix], lParam2.SubItems[ix]);
end
else // Dessending Sort
if nColumnToSort = 0 then
Result := CompareText(lParam1.Caption, lParam2.Caption)
else begin
ix := nColumnToSort - 1;
Result := -CompareText(lParam1.SubItems[ix], lParam2.SubItems[ix]);
end;
end;
begin
nColumnToSort := Column.Index;
bAssending := not bAssending;
ListView1.CustomSort(@CompareProc, nColumnToSort);
end;