我正在使用FastObjectListview,现在我需要对2列进行排序。因此,我尝试使用在StackOverflow网站上找到的示例,但无法正常工作。
请帮助。预先感谢。
Imports BrightIdeasSoftware
公共类表格1
Class MyCustomSortingDataSource
Inherits FastObjectListDataSource
Public Sub New(ByVal listView As FastObjectListView)
MyBase.New(listView)
End Sub
Public Property SortColumn As OLVColumn
Get
Return _sortColumn
End Get
Set(ByVal value As OLVColumn)
_sortColumn = value
End Set
End Property
Private _sortColumn As OLVColumn
Public Overrides Sub Sort(ByVal column As OLVColumn, ByVal sortOrder As SortOrder)
If sortOrder <> SortOrder.None Then
Dim objects As ArrayList = CType(Me.listView.Objects, ArrayList)
objects.Sort(New ModelObjectComparer(SortColumn, SortOrder.Ascending, column, sortOrder))
End If
Me.RebuildIndexMap()
End Sub
End Class
Class dlist
Public a As String
Public b As String
Public grp As Integer
End Class
Private Sub Form6_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim Data As New List(Of dlist)
Data.Add(New dlist With {.a = "First AB", .b = "Test 1", .grp = 1})
Data.Add(New dlist With {.a = "First ABC Test 3", .b = "Test 2", .grp = 1})
Data.Add(New dlist With {.a = "First ABC Test 1", .b = "Test 3", .grp = 1})
Data.Add(New dlist With {.a = "First ABC Test 2", .b = "Test 1", .grp = 1})
Data.Add(New dlist With {.a = "First ABCD", .b = "Test 3", .grp = 2})
Data.Add(New dlist With {.a = "First AB", .b = "Test 4", .grp = 2})
Data.Add(New dlist With {.a = "First AB", .b = "Test 4", .grp = 3})
Data.Add(New dlist With {.a = "First List", .b = "Test 4", .grp = 3})
Data.Add(New dlist With {.a = "First List ABC", .b = "Test 3", .grp = 3})
Data.Add(New dlist With {.a = "First List DBC", .b = "Test 4", .grp = 2})
Dim vSort As New MyCustomSortingDataSource(FastObjectListView1)
vSort.SortColumn = OlvGrp
FastObjectListView1.VirtualListDataSource = vSort
FastObjectListView1.Objects = Data
End Sub
结束班级