how to sort in Tlistview based on subitem[x]

℡╲_俬逩灬. 提交于 2019-11-30 19:19:33

Set SortType := stData and write

procedure TForm1.ListView1Compare(Sender: TObject; Item1, Item2: TListItem;
  Data: Integer; var Compare: Integer);
begin
  Compare := StrToInt(Item1.SubItems[x]) - StrToInt(Item2.SubItems[x])
end;

for instance. If compare is negative, Item1 should come before Item2; if compare is positive, the opposite applies. Thus this example, which assumes that SubItem[x] contains an integer, will sort the items according to the numerical value of SubItem[x].

If, on the other hand, SubItem[x] contains strings, then you can write

procedure TForm1.ListView1Compare(Sender: TObject; Item1, Item2: TListItem;
  Data: Integer; var Compare: Integer);
begin
  Compare := AnsiCompareText(Item1.SubItems[x], Item2.SubItems[x]);
end;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!