Public Class ListViewItemComparer
Implements IComparer
Private col As Integer
Public Sub New()
col = 0
End Sub
Public Sub New(ByVal column As Integer)
col = column
End Sub
Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements IComparer.Compare
If (String.Compare((CType(x, ListViewItem)).SubItems(col).Text, (CType(y, ListViewItem)).SubItems(col).Text) = 0) Then
Return String.Compare((CType(x, ListViewItem)).SubItems(0).Text, (CType(y, ListViewItem)).SubItems(0).Text)
Else
Return String.Compare((CType(x, ListViewItem)).SubItems(col).Text, (CType(y, ListViewItem)).SubItems(col).Text)
End If
End Function
End Class
类ListViewSorter:
Public Class ListViewSorter
Implements System.Collections.IComparer
Private SortIndex As Integer
Public Sub New(ByVal SortIndex As Integer)
Me.SortIndex = SortIndex
End Sub
Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements System.Collections.IComparer.Compare
Dim x1, y1 As System.Windows.Forms.ListViewItem