Results 1 to 6 of 6

Thread: [RESOLVED] remove Listview column sortorder

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2021
    Posts
    69

    Resolved [RESOLVED] remove Listview column sortorder

    I have a windows form with a Listview.
    When I click the header of the listview an arrow is shown to indicate the sorting order.


    Code:
        Private Sub ListView1_ColumnClick(sender As Object, e As ColumnClickEventArgs) Handles ListView1.ColumnClick
    
            Dim new_sorting_column As ColumnHeader =
            ListView1.Columns(e.Column)
    
            If e.Column = 0 Then
                Exit Sub
            End If
            Dim sort_order As System.Windows.Forms.SortOrder
            If m_SortingColumn Is Nothing Then
                sort_order = SortOrder.Ascending
            Else
                ' See if this is the same column.
                If new_sorting_column.Equals(m_SortingColumn) Then
                    If m_SortingColumn.Text.StartsWith(ChrW(&H25B2)) Then
                        sort_order = SortOrder.Descending
                    Else
                        sort_order = SortOrder.Ascending
                    End If
                Else
                    sort_order = SortOrder.Ascending
                End If
    
                ' Remove the old sort indicator.
                m_SortingColumn.Text =
                m_SortingColumn.Text.Substring(2)
            End If
    
            m_SortingColumn = new_sorting_column
            If sort_order = SortOrder.Ascending Then
                m_SortingColumn.Text = ChrW(&H25B2) & " " & m_SortingColumn.Text  'asc
            Else
                m_SortingColumn.Text = ChrW(&H25BC) & " " & m_SortingColumn.Text  'desc
            End If
    
            ListView1.ListViewItemSorter = New _
            ListViewComparer(e.Column, sort_order)
            ListView1.Sort()
        End Sub
    When I click a button the Listview is cleared. When that happens I want the arrow in the columnheader to be removed so it just shows the header title.
    Last edited by clausowitz; May 5th, 2021 at 02:51 PM.

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    33,400

    Re: remove Listview column sortorder

    Stab in the dark here, but try setting ListView1.ListViewItemSorter to Nothing when you clear the LV.


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2021
    Posts
    69

    Re: remove Listview column sortorder

    tg

    it doesn't remove the arrow from the columnheader

  4. #4
    Frenzied Member
    Join Date
    Jul 2011
    Location
    UK
    Posts
    1,335

    Re: remove Listview column sortorder

    Do you realise that it's your code that is adding the arrow?
    Code:
    m_SortingColumn = new_sorting_column
    If sort_order = SortOrder.Ascending Then
        m_SortingColumn.Text = ChrW(&H25B2) & " " & m_SortingColumn.Text  'asc
    Else
        m_SortingColumn.Text = ChrW(&H25BC) & " " & m_SortingColumn.Text  'desc
    End If
    So wherever you clear the Items collection, you should add code to rewrite the appropriate column header's Text without the arrow.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Apr 2021
    Posts
    69

    Re: remove Listview column sortorder

    Yes I did realise that.
    But I have no idea how to write the code

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,663

    Re: remove Listview column sortorder

    Try this:
    Code:
    m_SortingColumn.Text = m_SortingColumn.Text.SubString(2)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width