John Topley's Knowledgebase
Sorting A ListView
Friday, 30 May 2003
This Visual Basic code illustrates how to sort a ListView control when a column header is clicked in Details view. The sort order is toggled between ascending and descending.
Private Sub ListView1_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)
With ListView1
' Toggle the sort order.
If .SortOrder = lvwAscending Then
.SortOrder = lvwDescending
Else
.SortOrder = lvwAscending
End If
' Sort by the column that was clicked on.
.SortKey = ColumnHeader.Index - 1
End With
End Sub
top | index | previous | next | comments ()
|