Listview Column Sorting Problem

Creative2

Freshman
Joined
Jan 7, 2003
Messages
31
Location
Toronto, Canada
Hi Guys,

I m using sperate Icomparer classes for each column sorting, and they work fine, but when I fill the listview again, it gives me "invalid index value" error, or skips first two three rows subitems, I am using listview.items.clear() method prior to every time i fill the listview. Before writing the codes for sorting listview was working fine, someone has any idea why it is happening?

I would really appreciate your help.

CLASS:

Public Class lsvCompanyA
Implements IComparer
Public Function CompareTo(ByVal o1 As Object, ByVal o2 As Object) As Integer _
Implements System.Collections.IComparer.Compare

Dim item1, item2 As ListViewItem
item1 = CType(o1, ListViewItem)
item2 = CType(o2, ListViewItem)

If item1.ToString.ToUpper > item2.ToString.ToUpper Then
Return 1
Else
If item1.ToString.ToUpper < item2.ToString.ToUpper Then
Return -1
Else
Return 0
End If
End If
End Function
End Class

Column Click Event:

Select Case e.Column

Case 0
If lsvDetails.Sorting = SortOrder.Ascending = False Then
lsvDetails.ListViewItemSorter = New lsvCompanyA()
lsvDetails.Sorting = SortOrder.Ascending

ElseIf lsvDetails.Sorting = SortOrder.Descending = False Then
lsvDetails.ListViewItemSorter = New lsvCompanyD() (identical Class except returns opposite values as lsvCompanyA, for opposite sorting)
lsvDetails.Sorting = SortOrder.Descending

End If
 
Problem Solved

I added following codes at the end of each case statement in ColumnClickEvent, and now its working fine.

Mysorter = lsvDetails.ListViewItemSorter
Mysorter = Nothing
lsvDetails.ListViewItemSorter = Mysorter

(Mysorter declaration)

dim mysorter (in columnClickEvent).

Thanx a lot guys, if you have any questions please dont hesitate.
 
Back
Top