
slow list view sorting - help needed
In your columnsorter class the IsDate function is where the time goes. IsDate has a lot of code in it to check all different formats of dates which is pretty expensive in this case.
I made a slight modification of your code to keep track of which columns have Date date in them (of course this assumes you have to set that up ahead of time)
' I added this to your ColumnSorter class
Private m_ColIsDate() As Boolean
Public Property ColumnCount() As Integer
Get
Return m_ColIsDate.Length
End Get
Set(ByVal Value As Integer)
ReDim m_ColIsDate(Value)
End Set
End Property
Public Property DateColumn(ByVal ColId As Integer) As Boolean
Get
Return m_ColIsDate(ColId)
End Get
Set(ByVal Value As Boolean)
m_ColIsDate(ColId) = Value
End Set
End Property
' And initialized the column information before setting the ListView1.ListViewItemSorter property.
Dim liSorter As ColumnSorter
liSorter = New ColumnSorter(0, SortOrder.Ascending)
liSorter.ColumnCount = 1 ' I only have 1 column
liSorter.DateColumn(0) = True ' It's data type is DATE....
Hope this helps....
Thanks
Gary Spangler [MS VB QA]
--
This posting is provided "AS IS" with no warranties, and confers no rights.
Hi
When trying to sort listview controls, I find that its really slow, takes over a min on a P3 1GHz for 1000 records. I created a custom sorting class, please see attached vb file, and made an instance to the ListViewItemSorter (see below). When I click on the column of the listview I expect the control to sort within a few seconds, but it don't. How can I make this sort routine more efficient?
Many Thanks
Private Sub frmTest_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
lstResults.ListViewItemSorter = New ColumnSorter(1, SortOrder.None)
End Sub
Private Sub lstResults_ColumnClick(ByVal sender As Object, ByVal e As System.Windows.Forms.ColumnClickEventArgs) Handles lstResults.ColumnClick
Dim colSorter As ColumnSorter = CType(lstResults.ListViewItemSorter, ColumnSorter)
'Swap direction on each click
If colSorter.AscDirection = SortOrder.Ascending Then
colSorter.AscDirection = SortOrder.Descending
Else
colSorter.AscDirection = SortOrder.Ascending
End If
'Index to sort
colSorter.CompareIndex = e.Column
lstResults.Sort()
End Sub