How to tell when a Listbox is done sorting?

Is there a way to tell when a Listbox has finished sorting after a column header press?
I have a Listbox that I would like to re-position so the selected record is visible via ScrollPosition,
but I can’t figure out how to tell when the sort is completed.

You could add some code to the SortColumn event of the listbox to acheieve this.

Something else I have done in the past is to turn the column headers off and add custom buttons directly above the columns and add the relevant sort code to those buttons. Not sure if this would be frowned upon but it worked fine for me. The thing to watch out with this method is that if the listbox is resized, you need to resize the buttons accordingly.

I at least one record is selected prior to the pressing on the header, the Change event will fire after the sort has finished.

start a timer with period=0 and mode=1 in sort column event.
It fires when sorting is done and main loop continues.

Thanks everyone. I was thinking of adding some type of ‘sorting’ flag in the Sort or HeaderPressed events, but solution also requires some other code (or a timer) to watch for completion.

This actually works for what I need:

I didn’t think to look there as the LR states:

It does make sense, though:
If a row is Selected that row number will probably Change when sorted , so the Event does fire.

Thanks @Eli Ott !

I have other controls on the screen tied to the row selected and it looked bad when the Selection rolled off the visible list after a sort.

Have a look at Feedback case #19552. It might help to have new ideas.