R
rmorvay
I have successfully integrated sorting in the listview control with the
following code:
Private Sub ListView_ColumnClick(ByVal sender As Object, ByVal e As
System.Windows.Forms.ColumnClickEventArgs) Handles ListView.ColumnClick
If ListView.Sorting = System.Windows.Forms.SortOrder.Ascending Then
ListView.Sorting = System.Windows.Forms.SortOrder.Descending
Else
ListView.Sorting = System.Windows.Forms.SortOrder.Ascending
End If
Dim sorter As New SortOrder(e.Column)
ListView.ListViewItemSorter = sorter
End Sub
Private Class SortOrder
Implements IComparer
Dim Column As Integer
Public Sub New(ByVal aColumn As Integer)
Column = aColumn
End Sub
Public Function compare(ByVal x As Object, ByVal y As Object) As
Integer Implements IComparer.Compare
Dim xItem, yItem As System.Windows.Forms.ListViewItem
xItem = CType(x, ListViewItem)
yItem = CType(y, ListViewItem)
If xItem.ListView.Sorting =
System.Windows.Forms.SortOrder.Ascending Then
Return
(xItem.SubItems(Column).Text).CompareTo(yItem.SubItems(Column).Text)
Else
Return
(yItem.SubItems(Column).Text).CompareTo(xItem.SubItems(Column).Text)
End If
End Function
End Class
But I would like to easily add an up and down arrow when the column is
clicked. I am lousy with graphics so I don't know if this code can be
easily modified to handle this enhancement. A point in the right direction
would be greatly appreciated.
following code:
Private Sub ListView_ColumnClick(ByVal sender As Object, ByVal e As
System.Windows.Forms.ColumnClickEventArgs) Handles ListView.ColumnClick
If ListView.Sorting = System.Windows.Forms.SortOrder.Ascending Then
ListView.Sorting = System.Windows.Forms.SortOrder.Descending
Else
ListView.Sorting = System.Windows.Forms.SortOrder.Ascending
End If
Dim sorter As New SortOrder(e.Column)
ListView.ListViewItemSorter = sorter
End Sub
Private Class SortOrder
Implements IComparer
Dim Column As Integer
Public Sub New(ByVal aColumn As Integer)
Column = aColumn
End Sub
Public Function compare(ByVal x As Object, ByVal y As Object) As
Integer Implements IComparer.Compare
Dim xItem, yItem As System.Windows.Forms.ListViewItem
xItem = CType(x, ListViewItem)
yItem = CType(y, ListViewItem)
If xItem.ListView.Sorting =
System.Windows.Forms.SortOrder.Ascending Then
Return
(xItem.SubItems(Column).Text).CompareTo(yItem.SubItems(Column).Text)
Else
Return
(yItem.SubItems(Column).Text).CompareTo(xItem.SubItems(Column).Text)
End If
End Function
End Class
But I would like to easily add an up and down arrow when the column is
clicked. I am lousy with graphics so I don't know if this code can be
easily modified to handle this enhancement. A point in the right direction
would be greatly appreciated.