Listview Sorting Graphic in Column Header...

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top