Drag & drop insert rows into a listbox

I try to drag and drop insert rows into a listbox, with visual feedback about the place where the new row will go. In itemDragMove I draw a hightlight on the targeted row or between the rows (if the cursor is close to the border between the rows).

This works fine until the listbox gets scrolled. Then my little trick with getRowPosition and calculating the relative position of the cursor inside the row does not work anymore, because getRowPosition returns the absolute position of the row. That’s OK, but I did not find any way to calculate the pixel offset due to the (potentially smooth) scroll.

Any idea or maybe a better way to provide the visual feedback?


I’d suggest making the row components themselves drop-targets - they can draw a line at their top or bottom when you drag the item over them.

1 Like

Thanks for the idea, that works perfectly

Hi guys!!! I’m a newbie…
I would like to to the same thing…
but which class does what???
I had a try and did this:
MyDraggableList: public ListBoxModel, public DragAndDropContainer, public Component

which holds a ListBox* and a OwnedArray

and a DraggableItem which is a class from DragAndDropTarget.

I hoped this worked but the DraggableItems inside the OwnedArray
don’t “feel” if someone is over them…

I hope you’ll understand… poor english…