Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Custom sort of TListView?

15 views
Skip to first unread message

John Kelly

unread,
Aug 21, 2005, 5:09:00 AM8/21/05
to
Can anyone suggest a way to implement a custom sort for the TListView
component? I'm using Kylix3 OE.

An example would be even nicer :-)

JohnK

theo

unread,
Aug 21, 2005, 7:41:45 AM8/21/05
to
John Kelly schrieb:

Afaik there is no "built-in" way to custom-sort in TListView.
You can either add a column which contains the values you want to sort
by and then sort by this column, or (re-)fill the ListView already
sorted, i.e. sort externally maybe by using TList.Sort

John Kelly

unread,
Aug 21, 2005, 4:06:22 PM8/21/05
to
theo wrote:
> Afaik there is no "built-in" way to custom-sort in TListView.
> You can either add a column which contains the values you want to sort
> by and then sort by this column, or (re-)fill the ListView already
> sorted, i.e. sort externally maybe by using TList.Sort

Thanks Theo, I actually want to sort on the imageindex and then a
secondary sort on the selected column as I do in my Delphi application
version. If I have to code this sort myself what would be a good
algorithm? (I was off that day in CS class. ;-) The list could run
into two or three thousand items and would get filled and sorted on startup.

Angus Robertson - Magenta Systems Ltd

unread,
Aug 21, 2005, 7:44:00 PM8/21/05
to
In article <4308dea9$1...@newsgroups.borland.com>,
johnk.d...@gmail.com (John Kelly) wrote:
> If I have to code this sort myself what would be a good
> algorithm? (I was off that day in CS class. ;-) The list could run
> into two or three thousand items and would get filled and sorted on
> startup.

Really too many items for a Windows listview to handle if it allocated
all the memory for them, at least in VCL, not used CLX. Much faster to
use OwnerData, store all the data yourself and then the sorting is much
easier. There is no real algorithm, sorting is a simple compare of two
items, if you are sorting more than one column, you combine them to sort.

Angus

0 new messages