You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.5 KiB
58 lines
1.5 KiB
Public Class clsListViewItemComparer
|
|
|
|
Implements IComparer
|
|
|
|
Private _Column As Integer
|
|
Private _Numeric As Boolean = False
|
|
|
|
Public Property Column() As Integer
|
|
Get
|
|
Return _Column
|
|
End Get
|
|
Set(ByVal Value As Integer)
|
|
_Column = Value
|
|
End Set
|
|
End Property
|
|
|
|
Public Property Numeric() As Boolean
|
|
Get
|
|
Return _Numeric
|
|
End Get
|
|
Set(ByVal Value As Boolean)
|
|
_Numeric = Value
|
|
End Set
|
|
End Property
|
|
|
|
Public Sub New(ByVal ColumnIndex As Integer)
|
|
Column = ColumnIndex
|
|
End Sub
|
|
|
|
Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer _
|
|
Implements System.Collections.IComparer.Compare
|
|
Dim ListX As ListViewItem = CType(x, ListViewItem)
|
|
Dim ListY As ListViewItem = CType(y, ListViewItem)
|
|
If Numeric Then
|
|
Dim ListXVal, ListYVal As Decimal
|
|
Try
|
|
ListXVal = Decimal.Parse(ListX.SubItems(Column).Text)
|
|
Catch
|
|
ListXVal = 0
|
|
End Try
|
|
Try
|
|
ListYVal = Decimal.Parse(ListY.SubItems(Column).Text)
|
|
Catch
|
|
ListYVal = 0
|
|
End Try
|
|
|
|
Return Decimal.Compare(ListXVal, ListYVal)
|
|
Else
|
|
Dim ListXText As String = ListX.SubItems(Column).Text
|
|
Dim ListYText As String = ListY.SubItems(Column).Text
|
|
|
|
Return String.Compare(ListXText, ListYText)
|
|
End If
|
|
|
|
End Function
|
|
|
|
End Class
|