Avoid a listbox from being re-ordered possible?

Is there a way to avoid a listbox from being re-ordered which happens when clicking on the header? I need to see the header, but like to disable that order function.

See ColumnSortTypeAt

1 Like

You can prevent the re-ordering by returning True from the HeaderPressed event, but AFAIK you cannot prevent the sort arrow from appearing. I think I may have filed a report on this long ago.

That’s why is better to use ColumnSortTypeAt

You certainly can prevent the arrow from appearing. That is what the ColumnSortTypeAt is for. Pop the following into your listbox open event:

Me.ColumnSortTypeAt( 0 ) = DesktopListbox.SortTypes.NotSortable
Me.ColumnSortTypeAt( 1 ) = DesktopListbox.SortTypes.NotSortable
Me.ColumnSortTypeAt( 2 ) = DesktopListbox.SortTypes.NotSortable

or more generically:

For i As Integer = 0 To Me.LastColumnIndex
   Me.ColumnSortTypeAt( i ) = DesktopListbox.SortTypes.NotSortable

They don’t sort when clicked and they don’t show the sort arrow.

Actually, the following seems to work also:

Me.ColumnSortTypeAt( Me.AllColumns ) = DesktopListbox.SortTypes.NotSortable

Ah, I guess I may have been going about it in the wrong way, thanks :slight_smile:

No problem, it’s not the clearest of things, but at least you can get to where you need to be.

Thanks, Ian. The arrow disappeared. perfect solution!

This is even better, as you don’t need to know how many columns it has.

Me.ColumnSortTypeAt( Me.AllColumns ) = DesktopListbox.SortTypes.NotSortable