Delphi 如何基于子项[x]在Tlistview中排序

Delphi 如何基于子项[x]在Tlistview中排序,delphi,vcl,tlistview,Delphi,Vcl,Tlistview,如何在tlistview中排序子项[x]中存在的数据?设置排序类型:=stData并写入 procedure TForm1.ListView1Compare(Sender: TObject; Item1, Item2: TListItem; Data: Integer; var Compare: Integer); begin Compare := StrToInt(Item1.SubItems[x]) - StrToInt(Item2.SubItems[x]) end; 比如说。如果

如何在
tlistview
中排序
子项[x]
中存在的数据?

设置
排序类型:=stData
并写入

procedure TForm1.ListView1Compare(Sender: TObject; Item1, Item2: TListItem;
  Data: Integer; var Compare: Integer);
begin
  Compare := StrToInt(Item1.SubItems[x]) - StrToInt(Item2.SubItems[x])
end;
比如说。如果比较为负数,则项目1应位于项目2之前;如果比较为正,则相反。因此,本例假设子项[x]包含一个整数,将根据子项[x]的数值对项进行排序

另一方面,如果子项[x]包含字符串,则可以编写

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