-
May 5th, 2021, 01:27 PM
#1
Thread Starter
Lively Member
[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.
-
May 5th, 2021, 03:44 PM
#2
Re: remove Listview column sortorder
Stab in the dark here, but try setting ListView1.ListViewItemSorter to Nothing when you clear the LV.
-tg
-
May 5th, 2021, 03:48 PM
#3
Thread Starter
Lively Member
Re: remove Listview column sortorder
tg
it doesn't remove the arrow from the columnheader
-
May 5th, 2021, 04:22 PM
#4
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.
-
May 5th, 2021, 05:28 PM
#5
Thread Starter
Lively Member
Re: remove Listview column sortorder
Yes I did realise that.
But I have no idea how to write the code
-
May 5th, 2021, 05:35 PM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|