Results 1 to 2 of 2

Thread: Listview ColumnClick SortOrder

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2004
    Posts
    28

    Listview ColumnClick SortOrder

    This code sorts listview text columns but does not sort numeric columns properly. I appreciate any suggestions!

    Code:
    With ListView2
        .SortKey = ColumnHeader.Index - 1
        .Sorted = True
            If .SortOrder = lvwAscending Then
               .SortOrder = lvwDescending
            Else
               .SortOrder = lvwAscending
            End If
        .SortKey = ColumnHeader.Index - 1
    End With

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    listview is limited in that it only sorts on text and not on numeric... what I have done in some instances is format the number padding with 0s to the largest amount the field could be.. so if it could be a 5 digit number then i would load it to the list as


    Format$(MyNum,"00000")

    this will cause the sort to work, but depending on what you are doing, the 0s may be a pain in the arse. they are certainly ugly to look at....

    same thing for dates... i started loading dates into listview as yyyy-mm-dd because that will always sort correctly versus the more traditional mm/dd/yyy style used here in the US.


    If you goto MS website and search the KB, there is an article about sorting values via code, but I remember it was a lot of code. and using some shifty stuff to get it to work right...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width