Maya UI: How can I change the parent of a treeView item?

I am trying to build a hierarchical treeview, I need to reparent some of these items in pymel code, much the same as would happen if I middle mouse dragged them onto each other.

I could delete the item and use the addItem flag to add it back with a parent, however if the child node has any children of its own, they will be lost.

There doesn’t seem to be a “reparentItem” flag for treeviews.

From the docs:


Allow the user to perform drag and drop of treeView items.
If enabled, re-ordering / re-parenting operations can be perfomed with the middle mouse button.
This flag takes precendence over other drag and drop related flags. Defaults to true.