DragandDrop multiselection with treeview

Hi !

I’m trying to do DragandDrop with multiselection in a treeview…
With : virtual const String TreeViewItem::getDragSourceDescription () I DragandDrop only one item and I don’t achieve to draganddrop a group of items…

Thanks for your help


sorry, don’t understand the problem…? Just because you’re supplying one drag description doesn’t mean that the drag operation can’t involve multiple objects. When your target receives the event, it can just use all the items that were selected in the treeview.

But the method which returns a string of the draganddrop description is only implemented in TreeViewItem … not in TreeView.

With a listbox, I made :

const String OriginNavigatorBox::getDragSourceDescription (const SparseSet& selectedRows)
String desc;
for (int i = 0; i < selectedRows.size(); ++i)
desc << (selectedRows [i]) << T(" ");

    return desc.trim();


How can I do a similar thing with treeviews ?


Yes, but what I said before still applies - the drag target will be given a pointer to the treeview, so it can copy all the selected items if it wants to.

That string isn’t supposed to contain the data, just a description of what it’s for, e.g. “my treeview stuff”, so that potential drop targets can decide if they’re interested in it.

Ok I understood the role of the string.
But when I drag some rows of a listbox, I see these rows following the mouse when I move it.
When I try to drag some rows of a tree, I see only the last row I selected in the tree following the mouse.


Yeah, it’ll only show one row being dragged, but it’ll still do the job. You could probably override it to give it your own drag image if it’s important.

I have an other question on multiselection :

You have a listbox with multiselection enabled. You make a multiselection (with shift+leftbutton of the mouse for example) and then you click on a row of your selection. While you don’t release the button of your mouse, the selection appears. When you release, only the last row is selected.

With a treeview, even if you click on a row of your selection, it immediately selects the last row. Why ?


Probably because it needs fixing!

What do you mean with “fixing ?”


I’ve done it now - check out the tip and it’ll work.