Creative2
Freshman
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
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