-
Notifications
You must be signed in to change notification settings - Fork 0
/
lvwSorter.vb
44 lines (31 loc) · 1.13 KB
/
lvwSorter.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
Public Class lvsorter(Of T As IComparable)
Implements IComparer
Private column As Integer
Private tc As System.ComponentModel.TypeConverter
Public Sub New(ByVal column As Integer)
Me.column = column
tc = System.ComponentModel.TypeDescriptor.GetConverter(GetType(T))
End Sub
Public Function Compare(ByVal x As Object, ByVal y As Object) As _
Integer Implements System.Collections.IComparer.Compare
Dim lvi1 As ListViewItem = CType(x, ListViewItem)
Dim lvi2 As ListViewItem = CType(y, ListViewItem)
Dim arg1 As T
'If lvi1.SubItems(column).Text.Length > 0 Then
Try
arg1 = tc.ConvertFromString(lvi1.SubItems(column).Text)
Catch ex As Exception
End Try
Dim arg2 As T
Try
arg2 = tc.ConvertFromString(lvi2.SubItems(column).Text)
Catch ex As Exception
End Try
If lvi1.ListView.Sorting = SortOrder.Ascending Then
Return arg1.CompareTo(arg2)
Else
Return -arg1.CompareTo(arg2)
End If
'End If
End Function
End Class