How to trigger code after DragReorderRows?

I’m stuck trying to get some code to trigger after drag reordering a row in a ListBox (it’s a music playlist).

I want to do this to renumber the values in column 1 to (1,2,3,…i) because after the drag I’d have for example (1,4,2,3…i)

  dim i as integer
  for i = 0 to AlbumsTracksList.ListCount - 1
    AlbumsTracksList.cell(i,0) = str(i+1)
  next i

How would I get it to fire after the reorder has finished? If I put this in the DragReorderRows event it runs but of course the value is overwritten when the event ends and returns false! Do I have to deal with the entire reorder myself with something like this? https://forum.xojo.com/17437-listbox-dragging-problem

What if you call a Timer at the end of the DragReorder that runs your for loop?

1 Like

Yep that does the trick - and I learned the usefulness of Timer Single Mode. Thanks very much!

The Change event fires after the dragged row is dropped.

1 Like

Yes but I don’t really need the code to run whenever a row is selected either.

As it hapens in this case it wouldn’t really matter but I may come across a situation in future where it would.

in celltext paint just set the cell to the value you want displayed
its updated immediately when the cell draws

something like
celltextPaint
if row < 0 or row > me.ListCount-1 then return false
if column <> 0 then return false
me.cell(row,column) = str(row+1)

no timer required

1 Like

[quote=162728:@Norman Palardy]in celltext paint just set the cell to the value you want displayed
its updated immediately when the cell draws

something like
celltextPaint
if row < 0 or row > me.ListCount-1 then return false
if column <> 0 then return false
me.cell(row,column) = str(row+1)

no timer required[/quote]

Oh yeah that’s a great idea - so far in my adventure into Xojo I’d only thought of using CellTexPaint and CellBackgroundPaint for updating the display not the actual values (which I’ll need later). The timer method does have the potential to not fire on a slow or ‘busy’ machine which had me worried. I’ll give it a shot tomorrow. Thanks Norman.