Another Listview sorting Question

ZeroEffect

Junior Contributor
Joined
Oct 24, 2004
Messages
204
Location
Detroit, MI
I have been through the forum and I have seen many examples of listview sorting but In this one instance I can't get it to work.

I am loading a Listview from dbf file if the item found in the db meet the criteria it is added to the listview. No problem I get a full listview of items I wanted. Now the first column is time in the 24 hour format. So I want to sort the column accending, (00:00:00 ==> 24:59:59) I have a class for the listview Item comparer that looks like this.
Visual Basic:
Public Class ListViewItemComparer
    Implements IComparer

    Private col As Integer

    Public Sub New()
        col = 0
    End Sub

    Public Sub New(ByVal column As Integer)
        col = column
    End Sub

    Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer _
       Implements IComparer.Compare
        On Error Resume Next
        Return [String].Compare(CType(x, ListViewItem).SubItems(col).Text, CType(y, ListViewItem).SubItems(col).Text)
    End Function
End Class
and is called like this
Visual Basic:
lv.ListViewItemSorter = New ListViewItemComparer(1)
lv.Sort()

but I still get a couple of entries out of wack. The first column will look like this.

00:00:00
01:00:00
12:00:00
20:00:00
17:00:00
23:00:00

This will stay this way even if I call the sort after the Listview is done being loaded. Also If I add a new item to the db it'll be placed at the bottom and not sorted. I have stepped through the code but nothing sticks out.

Any thoughts?

Thanks

ZeroEffect
 
Last edited:
Found it I am a Jack A#$. It helps if you sort the right column.
I also removed the On error line and changed it to a try catch end try.

All is good.

Thanks

ZeroEffect
 
Back
Top