Listview Sorting Graphic in Column Header...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • rmorvay

    #1

    Listview Sorting Graphic in Column Header...

    I have successfully integrated sorting in the listview control with the
    following code:

    Private Sub ListView_Column Click(ByVal sender As Object, ByVal e As
    System.Windows. Forms.ColumnCli ckEventArgs) Handles ListView.Column Click

    If ListView.Sortin g = System.Windows. Forms.SortOrder .Ascending Then
    ListView.Sortin g = System.Windows. Forms.SortOrder .Descending
    Else
    ListView.Sortin g = System.Windows. Forms.SortOrder .Ascending
    End If

    Dim sorter As New SortOrder(e.Col umn)
    ListView.ListVi ewItemSorter = 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.Compa re
    Dim xItem, yItem As System.Windows. Forms.ListViewI tem

    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(Colum n).Text)
    Else
    Return
    (yItem.SubItems (Column).Text). CompareTo(xItem .SubItems(Colum n).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.


Working...