我正在使用 Delphi 2010 和 TListView 来列出名称和其他数据。前两列是姓氏和名字
Caption = Last Name
SubItems[0] = First Name
如何按这两列对 ListView 进行排序?这些只是 ListView 排序的列,我希望始终保持这样的排序(添加、编辑、删除项目时)
我怎样才能做到这一点?
最佳答案
将 SortType
设置为“stBoth”,并实现 OnCompare
事件处理程序。示例:
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;
关于delphi - TListView 列排序(按前两列排序),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15057886/