ListBox Copy Multiple Rows

I want to be able to option-click-drag to copy single or multiple (not necessarily contiguous) rows in a (desktop) ListBox. There are old posts on the forum about this and similar questions, including one from a user who says he “got it all working”, but unhelpfully didn’t share any details. I’m pretty sure I myself had it working in RealStudio days, but now I’m older and stupider and don’t have a computer that can run RealStudio.

The main stumbling point for me at the moment is that if I use AddItem to add a row’s contents to the DragItem in the DragRow event, neither DragReorder nor DropObject fire anymore, nor does the built-in row-dragging stuff kick in, like the visual insertion line - basically row dragging just stops working altogether. AddItem seems ideal for this situation but I guess I can work around it by glomming all the rows together in a big delimited string and parsing it in DropObject, but it’d be cleaner to use AddItem.

Allow Row Dragging and Allow Reordering are both enabled in the Inspector. In the DragRow event I have:

For listrow = 0 To Me.LastRowIndex
  If listrow=row Or Me.Selected(listrow)  Then
    // Have to iterate over columns because we need to encode any checkboxes
    For ListCol = 0 To Me.LastColumnIndex
      If Me.CellType(listrow,ListCol) = Me.TypeCheckbox Then
        drag.Text = Str(CType(Me.CellCheck(listrow,ListCol),Integer))
      Else
        Drag.Text = Me.Cell(listrow,ListCol)
      End
         drag.AddItem(0,0,0,0) // This stops row dragging from working
    Next
  End
Next

It doesn’t seem to matter whether I return True or False from DragRow. If I comment out the AddItem line, the built-in system works again, but then of course my row data isn’t stored in the DragItem. What am I doing wrong?

you have to return true from dragenter for the dragrow or dragrowreorder to fire
bug “fixed” in 2024r4 that made me search a lot recently !
previously it always fired.

DragRow and DragReorderRows do fire for me without returning anything from DragEnter, as long as I don’t call Additem in DragRow. If I do call AddItem in DragRow, DragEnter doesn’t fire either.

do you call drag.drag somewhere ?

No. I tried calling it after using AddItem in DragRow, but it had no effect.

I created a ListBox subclass that implements drag-copy, it was a bit of a brain-twister, so I’ll leave it here in case anyone needs it in future.

Screen Recording 2025-06-06 at 8.49.16 AM (1) (1)

Drag-Copy ListBox Demo.xojo_binary_project.zip (8.2 KB)

The issue of AddItem inhibiting the framework events hasn’t really been answered, so I won’t mark the thread as “Solved” :slight_smile:

2 Likes