I have a TListview with 4 columns (which are all strings of course) however, I store data in them as such:
Caption
: any stringSubItems[0]
: integer, e.g.'5016'
SubItems[1]
: date, e.g.'03/22/13'
Subitems[2]
: any string
I use the following code to sort when user clicks a column header
I was looking at this post "how to sort in Tlistview based on subitem[x]" but I can't figure out how to take the different column types into consideration.
procedure TfrmFind.lvwTagsColumnClick(Sender: TObject; Column: TListColumn);
begin
ColumnToSort := Column.Index;
(Sender as TCustomListView).AlphaSort;
end;
procedure TfrmFind.lvwTagsCompare(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;
How can I take into consideration of the Integer and Date columns so they are not sorted as strings?
Thanks