Hi, I am trying to work out how to rearrange rows in a table list box through drag and drop. Could somone please point me in the right direction for how I might do this?
My data is stored in a value tree which I assume I would have to reorder once the drag and drop is complete.
I have done something similar (drag-and-drop row rearrangement) but TableListBox
wasn’t powerful enough in that case so I had to roll my own. But if all you need really is just rearranging simple list items, it does sound like TableListBox
can do it. It’s a bit hacky -
- In each cell component store a pointer to the parent
TableListBox
; - Override the drag event and use
TableListBox::getCellPosition
(and maybe binary sort?) to check which row would be the updated index; - Let the cell component modify the value tree and attach a listener to apply the changes back to
TableListBoxModel
.
Thankyou for the help, I really apreciate it!
I had a look at Drag and Drop containers and seem to have managed to have got that working. I made the MainComponent of my app into a D&D container and the table in to a D&D target. I am playing with overiding these functions to get it to drop in the right place:
void itemDragEnter(const SourceDetails& /dragSourceDetails/) override;
void itemDragMove(const SourceDetails& /dragSourceDetails/) override;
void itemDragExit(const SourceDetails& /dragSourceDetails/) override;
void itemDropped(const SourceDetails& dragSourceDetails) override;