TListView列排序(按前两列排序)

编程入门 行业动态 更新时间:2024-10-28 14:37:03
本文介绍了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列排序(按前两列排序)

本文发布于:2023-10-28 02:33:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1535251.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:TListView   按前两列

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!