Skip to main content

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

Comments