ValueTreesDemo - how to prevent dragging items to different parents?

Hi there,

I’m playing around with this demo trying to learn the TreeViewItem class.

Is there any (simple) way to prevent dragging items to a different parent. So that when the user drags any item, that item will always end up with the same parent.

The end result is that the entire tree’s hierarchy is prevented from being changed by the user regardless of how they move items within any parent.

Thanks in advance for your help and ideas.

You can do it the other way round:

Each TreeViewItem inherits DragAndDropTarget, so you can override isInterestedInDragSource() and make it return only true for it’s own children.
After doing so, none will accept a drag from a different parent.

1 Like

Thanks heaps! For whoever’s interested, the following modifications to the tutorial appear to work:

    var getDragSourceDescription() override
        return getParentItem()->getUniqueName();

    bool isInterestedInDragSource (const DragAndDropTarget::SourceDetails& dragSourceDetails) override
        return dragSourceDetails.description == getUniqueName();

1 Like