
listview sort on integer question
Quote:
>has integers in them (from 0-19). Why is it that when I set the .SORTED
>= true
>and the .SORTKEY to the column, it sorts in this fashion:
>0
>1
>10
Because all items in the listview are strings, so it is sorting the strings,
not the number. You'll have the same problem with dates. There are various
ways around this. The easiest is to add a "hidden" column by setting that
columns width to zero, then, if the user clicks on the header of the numeric
column, run through all items and load the "hidden" column with a sortable
string value, something like
format$(.listitems(index).subitems(3),"0000000000") or whatever, then, sort
the list by the "hidden" column programmatically. The reason I keep putting
quotes around "hidden" is because the user can resize the column and thus it
is not hidden any more. To stop them from doing this, you need to subclass
the listview and intercept resize and double click events. I have code to
do this if you are interested.
I've also seen another solution (also using subclassing) that writes a
custom "compare" subroutine to compare the list values and return the
highest one. (I think I got it from the knowledge base). The problem with
this is that in the end, the list "appears" sorted to the user, but if you
iterate through the items programmatically, you get them in the original
order. Since both methods involve subclassing, I prefer the first method.