'Unsort' a Listbox

I would like to be able to ‘Unsort’ a listbox without adding a column that has row numbers.

When you click a column header of a listbox, a little up arrow appears and the listbox is sorted. Click again and a down arrow appears and it’s sorted the other way around.
I figured it would be easy that if a user clicks the 3rd time on the header, the arrow would go away and the listbox would be how it was initially (unsorted).

I’ve put this in the ‘HeaderPressed’ event of a Listbox.

If Me.SortedColumn = column Then
  If Me.ColumnSortDirection(column) = -1 Then
    Me.ColumnSortDirection(column) = 0
    // <--- I tried Me.Sort, Me.Refresh, Me.Invalidate etc. here
    FillListBox()  // <--- does a DeleteAllRows and fills it again.
  End If
End If

With the above code, I’d hoped that after the 3rd click on ta column header, the Listbox would reinitialize but it doesn’t. In fact, the columns can’t be sorted anymore and the arrow doesn’t go away.

Does anyone know what the best is to Unsort or reset a Listbox?

an added tag on the original row (rowtag or celltag) that is the “original line number” so the third click can sort by that

Is there a way to reset the header arrow showing the current sort direction to no-arrow as it’s when the listbox is not sorted?

In HeaderPressed of the Listbox the following

me.SortedColumn = -1 //----- remove sort arrows step 1 me.HasHeading = False //----- remove sort arrows step 2 me.HasHeading = True //----- remove sort arrows step 3

[quote=214124:@Kevin Pattison]In HeaderPressed of the Listbox the following

me.SortedColumn = -1 //----- remove sort arrows step 1 me.HasHeading = False //----- remove sort arrows step 2 me.HasHeading = True //----- remove sort arrows step 3[/quote]

Nice trick, and it works. Thanks!

[quote=214124:@Kevin Pattison]In HeaderPressed of the Listbox the following

me.SortedColumn = -1 //----- remove sort arrows step 1 me.HasHeading = False //----- remove sort arrows step 2 me.HasHeading = True //----- remove sort arrows step 3[/quote]
Thank you for this trick!

xDev 12.6, Tips & Tricks, Tip 4:

Tip 4: ListBox: Clear the selected Column

If you want to clear the selection of a listbox’s header then you can use

Listbox1.HeadingIndex = -1

However HeadingIndex is “obsolete” and you should use SortedColumn instead. Except that doing

Listbox1.SortedColumn = -1

does not remove the selection. Until this bug is fixed (obviously not a high priority, see reports #15616 & #18623) you need to trick Xojo into redrawing the header with

// No longer sorted, deselect col header. me.SortedColumn = -1 // this clears the sorting internally me.HasHeading = false // these two lines redraw the listbox header me.HasHeading = true