List View Sort Question 
Author Message
 List View Sort Question

I'm having a problem sorting correctly using the listview control. When
it sorts, it displays integer values alphabetically instead of
numerically. For instance, 2000 comes before 209 but I want 2000 to
come after 209. Any help is appreciated.

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Sun, 14 Jul 2002 03:00:00 GMT  
 List View Sort Question
Yep, Isn't that a complete pain in the ass!!!
There are two approaches neither pretty.
One involves a Callback which implements  a custom Compare routine (I am not
going there!).
The other involves creating a Dummy column, populating it with a"0"  padded
version of your
data (so it will sort correctly), Sort on that Dummy Column and then Remove
the Column!
SUCKS! DOESN'T IT!!! Any M$ folks{*filter*} out? Consider that my suggestion
for Ver 7.
Neila
Quote:

> I'm having a problem sorting correctly using the listview control. When
> it sorts, it displays integer values alphabetically instead of
> numerically. For instance, 2000 comes before 209 but I want 2000 to
> come after 209. Any help is appreciated.

> Sent via Deja.com http://www.*-*-*.com/
> Before you buy.



Sun, 14 Jul 2002 03:00:00 GMT  
 List View Sort Question
You need to format your numbers with leading zeros.  If you do not want to
display the numbers with leading zeros, create an invisible column with the
same data as the display column, but with leading zeros and sort by that
column instead.  You need enough zeros to pad every number out to the length
of the longest number present in the column.  It's a bit of a pain, but
there is no easier way to do it!  Use the Format function built in to VB.
Quote:

> I'm having a problem sorting correctly using the listview control. When
> it sorts, it displays integer values alphabetically instead of
> numerically. For instance, 2000 comes before 209 but I want 2000 to
> come after 209. Any help is appreciated.

> Sent via Deja.com http://www.deja.com/
> Before you buy.



Sun, 14 Jul 2002 03:00:00 GMT  
 List View Sort Question

Quote:

>Yep, Isn't that a complete pain in the ass!!!
>There are two approaches neither pretty.
>One involves a Callback which implements  a custom Compare routine (I am not
>going there!).
>The other involves creating a Dummy column, populating it with a"0"  padded
>version of your
>data (so it will sort correctly), Sort on that Dummy Column and then Remove
>the Column!
>SUCKS! DOESN'T IT!!! Any M$ folks{*filter*} out? Consider that my suggestion
>for Ver 7.
>Neila

The problem with (1) is that the listitems collection become out of synch
with the actual listview.  At that point you are better off rewriting the
whole COM listview object yourself in VB around an API-created listview.
To do that right would take a good developer a LONGGGG time, probably
months.

The problem with (2) is that you are (a) modifying the column data and
(b) it won't work right with many date formats regardless of padding.

On a current client's project, I opted to go with (c), a custom ActiveX
control wrapping the listview which stores data objects implementing
several custom interfaces.  One of the interfaces supports sorting by
data stored in variants.  Hence, instead of trying to sort strings in
listview, you instead sort collections of data/business objects by their
values, whether dates, strings, longs, etc.  The downside is you have to
clear out the listview, sort the data objects, repopulate the listview,
and go on as if no magic had happened.  Fortunately, VB can write pretty
fast sorts, so reasonable listviews can sorted in a fraction of a second.

Matthew Cromer
President, SDA Consulting, Inc.

http://www.*-*-*.com/



Mon, 15 Jul 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. slow list view sorting - help needed

2. Sorting the content of list view on clicking column headers

3. List view and sorting

4. List View Sort order

5. Logical sorting in List View (date and/or time)

6. List View Column Sorting

7. list view to sort

8. List View click on header to sort date column

9. List View - Sort by Clicking Header

10. LIST VIEW - FILE SIZE SORT

11. Help:list view control sorting

12. List View Sort

 

 
Powered by phpBB® Forum Software