根据子项[x]在Tlistview中如何排序 [英] how to sort in Tlistview based on subitem[x]

查看:116
本文介绍了根据子项[x]在Tlistview中如何排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果在 tlistview 中以 subitem [x] 中的数据排序

How to sort in tlistview with data present in subitem[x]?

推荐答案

设置 SortType:= 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;

如果比较为负,则Item1应该在Item2之前;如果比较是肯定的,则相反。因此,这个假设SubItem [x]包含一个整数的例子将根据SubItem [x]的数值对项目进行排序。

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].

如果在另一个手,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;

这篇关于根据子项[x]在Tlistview中如何排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆