Страницы

Поиск по вопросам

пятница, 12 июля 2019 г.

Сортировка колонок в ListView по нажатию

Как реализовать сортировку колонок в ListView по нажатию на название колонки?


Ответ

RTFM TListView.CustomSort Параметры метода - адрес функции сравнения (возвращающая -1,0,1 для двух элементов), и произвольное число, куда можно передать индекс колонки, которую нажали. function CustomSortProc(Item1, Item2: TListItem; ParamSort: integer): integer; stdcall; begin if ParamSort=0 then Result := CompareText(Item1.Caption,Item2.Caption) else if Item1.SubItems.Count>ParamSort-1 then begin if Item2.SubItems.Count>ParamSort-1 then Result := CompareText(Item1.SubItems[ParamSort-1],Item2.SubItems[ParamSort-1]) else Result := 1; end else Result:=-1; end;
procedure TForm1.ListView1ColumnClick(Sender: TObject; Column: TListColumn); begin ListView1.CustomSort(@CustomSortProc, Column.Index); end;

Комментариев нет:

Отправить комментарий