Im trying to sort a listview on subitems and cant seem to figure it out. I have read some about the icomparer which I also have yet to conquer. Any help would be appreciated.
Thanks, Matt
Private Sub ZipListView_ColumnClick(ByVal sender As Object, ByVal e As System.Windows.Forms.ColumnClickEventArgs) Handles ZipListView.ColumnClick
ColumnClick(e.Column)
End Sub
Public Sub ColumnClick(ByVal ColumnHeader As Integer)
If ZipListView Is Nothing Then Exit Sub
With ZipListView
'.SortKey = ColumnHeader.Index - 1
If intSortOrder = SortOrder.Ascending Then
intSortOrder = SortOrder.Descending
Else
intSortOrder = SortOrder.Ascending
End If
.ListViewItemSorter = New ListViewItemComparer(ColumnHeader, intSortOrder)
' Call the sort method to manually sort.
.Sort()
End With
End Sub
' Embedded Class
Class ListViewItemComparer
Implements IComparer
Private mintcol As Integer
Private mintSortOrder As System.Windows.Forms.SortOrder = SortOrder.Ascending
Private mblnIgnoreCase As Boolean
Public Sub New()
mintcol = 0
mintSortOrder = SortOrder.Ascending
mblnIgnoreCase = False
End Sub
Public Sub New(ByVal column As Integer, _
ByVal SortOrder As System.Windows.Forms.SortOrder, _
Optional ByVal IgnoreCase As Boolean = False)
mintcol = column
mintSortOrder = SortOrder
mblnIgnoreCase = IgnoreCase
End Sub
Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer _
Implements System.Collections.IComparer.Compare
Dim returnVal As Integer = -1
Thanks John! Great tip and useful piece of code, I went ahead passed the ListView into the columnclick sub so I can utilize it with all my listviews. Thanks again,
Matt
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.