TreeView and Drag&Drop question


#1

I’m currently enjoying the DragAndDropContainer part of a TreeView.

That’s great.
Though I’d like to be able to drag a selection of TreeViewItems, not an alone TreeViewItem.

Is a way or existing method to that ?

Best,

AsR


#2

I did this once but I don’t remember exactly how.
I think in the methods startDragging, itemDragEnter, itemDragMove, itemDropped, you get a pointer to the Treeview itself. So you have access to the selected items. Then you just have to copy these items in your target.

Hope this help.
Kevin


#3

Much thanks.
Thats a good point… you dont see the selection dragging though… but.


#4

[quote=“asair”]Much thanks.
Thats a good point… you dont see the selection dragging though… but.[/quote]

It’s not painfully difficult to create fake drag images if needed.


#5

I thought I would ask this here instead of starting another thread.

I am trying to drag a file from a FileTreeComponent onto another component. I have the basics working and the target component is receiving the itemDropped (const SourceDetails& dragSourceDetails)function but I can’t figure out how to get the file path from dragSourceDetails.

Any help would be appreciated.


#6

Answer:

http://rawmaterialsoftware.com/viewtopic.php?f=2&t=5526&hilit=filetree


#7

Thanks but I still don’t get it.

I tried several ways but it crased on getNumSelectedItems() becasue of a invlad index:

FileTreeComponent *pTree = (FileTreeComponent*) &dragSourceDetails.sourceComponent; for ( int i = 0; i < pTree->getNumSelectedFiles(); i++ ) //Crashes here { File f = pTree->getSelectedFile( i ); /*...*/ }

Please help with actual code.


#8

this is more c++ problem …

Never! Never! use these old c-style casts : (FileTreeComponent*) &dragSourceDetails.sourceComponent;

Use the FileTree pointer directly , if you saved it, or use a dynamic_cast<FileTreeComponent*> but check it first != 0


#9

OK I figured it out, but would like to kn ow how to access the fileTreeComponent directly. SPECIFIC CODE PLEASE!

Thanks