slow list view sorting - help needed 
Author Message
 slow list view sorting - help needed

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

  ColumnSorter.vb
1K Download


Tue, 12 Jul 2005 03:55:17 GMT  
 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



Tue, 12 Jul 2005 05:31:08 GMT  
 slow list view sorting - help needed

Thank you very much

Regards
Gary Howlett



Tue, 12 Jul 2005 05:49:39 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Help:list view control sorting

2. List View Contents Printing HELP NEEDED!!!!

3. Need help to create Explorer-Like view with Tree/List control

4. Sorting the content of list view on clicking column headers

5. List view and sorting

6. List View Sort Question

7. List View Sort order

8. Logical sorting in List View (date and/or time)

9. List View Column Sorting

10. list view to sort

11. List View click on header to sort date column

12. List View - Sort by Clicking Header

 

 
Powered by phpBB® Forum Software