How to detect a sort of a Listbox? Timer?

What is the process for detecting sorting of a Listbox is complete?
The factory sort supplied by XOJO works, but I can’t tell it’s complete in the event.
I would like to have some code at the end of Listbox.SortColumn.
I read adding a timer by code would work and fire after the sort is complete, but it doesn’t seem to work.

This is the code for a timer in Listbox.Sortcolumn

Dim atime As New Timer atime.Mode = 0


Two mistakes here.

  1. The timer will run out of scope and never fire
  2. The timer mode is set to Mode=Timer.ModeOff (0)

It might be better to try this, add a method to your Window: SortCompleted

In the Listbox.CompareRows add this code:

Xojo.core.timer.CancelCall(AddressOf SortCompleted) Xojo.core.Timer.callLater(50, AddressOf SortCompleted)

SortCompleted method would then be called 50ms after Listbox has finished sorting.

Jeremie, that might turn out to slow the sort down a lot. I’d put that code in the SortColumn event instead so it’s only called once.

So I followed instructions and put the above in the SortColumn event, and added the method “SortedColumn”, and I’m not sure it worked.

I have for the rowtag the row number.
After the timer fires (it can’t go to the next line until it has finished), a method called CpyRwTgtoArray

whose code is

Dim i As Integer Redim SrtdArray(-1) If AdCardList.ListCount-1 <> ArUbnd Then MsgBox"Serious Error" For i = 0 To AdCardList.ListCount-1 SrtdArray.Append AdCardList.RowTag(i) Next //SrtdArray is integer array. AdCardList is the Listbox. Return

The SrtdArray should have a jumble of numbers but it doesn’t.

Should the next method after the timer produce a jumble of numbers?

Other question. Do I ever call the method Listbox.Sort ???

I have a solution for you, no Timer needed. In a nutshell, I subclassed Listbox and implemented the SortColumn and CellBackgroundPaint events. The former raises the event and, if false, sets a flag then returns false. The latter checks the flag and, if true, raises an AfterSort event. The trick here is that CellBackgroundPaint will fire after sorting is complete so it’s a natural place to raise that event.

I created a sample project that you can find here:

Thank you Kem. It works perfectly.
My SrtdArray had a jumble of numbers.
Now I can figure out how to add my own event for dragRows