Pages

Thursday, March 10, 2011

VB6 Listview Sort when clicking the columnheader

Listview1 is the name of the listview control

Private Sub ListView1_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)
    With ListView1
        If .SortKey <> ColumnHeader.Index - 1 Then
            .SortKey = ColumnHeader.Index - 1
            .SortOrder = lvwAscending
        Else
            If .SortOrder = lvwAscending Then
                .SortOrder = lvwDescending
             Else
                 .SortOrder = lvwAscending
            End If
        End If
        .Sorted = -1
    End With
End Sub

Visit my blog @ http://jaypeeee.blogspot.com/
 

16 comments:

  1. with all the available answers i have found in the web, this is the one that is really helpful and effective.
    thank you very much! :D

    ReplyDelete
  2. it works flawlessly.. just copy to your project, voila.. ;) Best and the simplest answer in the web..
    thx a lot m8!!

    ReplyDelete
  3. wow... it works....!!!! it really works!!!! I'm so glad.. Thank you so much...

    ReplyDelete
  4. Excellent, thank you. So many complex versions elsewhere, good to find your nice concise version.

    ReplyDelete
  5. very usefull ... thank you ...

    ReplyDelete
  6. Thanks for article, very useful

    ReplyDelete
  7. Thank you dude!
    It helpful in 2016!

    ReplyDelete
  8. Thanks for saving my time

    ReplyDelete
  9. Thanks
    That is a clever and elegant code solution

    ReplyDelete
  10. Very useful! Simple and effective. Thanks a lot!!

    ReplyDelete