Unit Unit1;
Interface
Uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls;
Type
TForm1 = class(TForm)
ListView1: TListView;
procedure ListView1ColumnClick(Sender: TObject; Column: TListColumn);
procedure ListView1Compare(Sender: TObject; Item1, Item2: TListItem;
Data: Integer; var Compare: Integer);
End;
Var
Form1: TForm1;
ColumnToSort:Integer;
Implementation
{$R *.dfm}
Procedure TForm1.ListView1ColumnClick(Sender: TObject;
Column: TListColumn);
Begin
ColumnToSort := Column.Index;
(Sender as TCustomListView).AlphaSort;
End;
Procedure TForm1.ListView1Compare(Sender: TObject; Item1, Item2: TListItem;
Data: Integer; var Compare: Integer);
Var
ix: Integer;
Begin
If ColumnToSort = 0 then
Compare := CompareText(Item1.Caption,Item2.Caption)
Else begin
ix := ColumnToSort - 1;
Compare := CompareText(Item1.SubItems[ix],Item2.SubItems[ix]);
End;
End;
End.