TListView列排序(按前两列排序) [英] TListView Column Sort (Sort by first two columns)

查看:92
本文介绍了TListView列排序(按前两列排序)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Delphi 2010和TListView列出名称和其他数据。前两列是姓氏和名字

I am using Delphi 2010 and TListView to list Names and other data. The first two columns is the Last Name & First Name


标题=姓氏

子项[0] =名字

Caption = Last Name
SubItems[0] = First Name

如何按这两列对ListView进行排序?这些只是Listview的排序依据,我想一直保持这种排序(添加,编辑,删除项目时)

How do I sort the ListView by these two columns? These will only be the columns the Listview will be sorted by and I would like to always keep the sort as such (when adding, editing, deleting items)

推荐答案

SortType 设置为'stBoth',并实施 OnCompare 事件处理程序。示例:

Set SortType to 'stBoth', and implement an OnCompare event handler. Example:

procedure TForm1.ListView1Compare(Sender: TObject; Item1, Item2: TListItem;
  Data: Integer; var Compare: Integer);
var
  S1, S2: string;
begin
  S1 := Item1.Caption;
  if Item1.SubItems.Count > 0 then
    S1 := S1 + Item1.SubItems[0];
  S2 := Item2.Caption;
  if Item2.SubItems.Count > 0 then
    S2 := S2 + Item2.SubItems[0];

  Compare := CompareText(S1, S2);
end;

这篇关于TListView列排序(按前两列排序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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