[Closed] Drag and Drop in Treeview in .NET
Has anyone been able to get the Drag and Drop to work with the new .NET controls for the treeview?
In AxtiveX it was pretty simple, you just set a property to tell it what to do…
<ActiveXTreeview>.OLEDragMode = #ccOLEDragAutomatic
<ActiveXTreeview>.OLEDropMode = #ccOLEDropManual
In .Net I can NOT get it to work and it is driving me CRAZY. Please tell me someone has done it.
-Paul
Yeah, I hear you,
Took me a while to get this working…
the idea is that to enable the drag and drop, you need to use ‘DragDropEffects’ properties
of the argument of the draganddrop functions, and the ‘dodragdrop’ function
Here is what I came with:
(there probably are better ways)
-- the treeview in the rollout
dotNetControl tv "TreeView"
-- local viariables in the rollout
local DragNode, DropNode
local m=dotNetClass "System.Windows.Forms.DragDropEffects" -- Drag and drop effects
-- In the tv init function
tv.AllowDrop = true -- allow DragandDrop for the Treeview
-- DRAG AND DROP HANDLERS --
-- START Drag and Drop
on tv ItemDrag arg do
(
dragnode=arg.item
tv.doDragDrop arg.item m.Move -- this actually starts the drag and drop process
)
-- INSIDE Drag and Drop
on tv DragOver arg do
(
pos=tv.PointToClient tv.MousePosition -- this gave me a hard time to find out !
TestNode= tv.GetNodeAt pos
if testNode != undefined then -- OK to Drop
(
arg.Effect=arg.AllowedEffect
)
else -- NOT OK to Drop
(
arg.Effect=m.none
)
)
-- END Drag and Drop (drop the item)
on tv DragDrop arg do
(
pos=tv.PointToClient tv.MousePosition
DropNode=tv.GetNodeAt pos
dragNode.remove() -- need to remove the node from the tree
dropNode.Nodes.add dragNode -- add it to the dropNode children
)
Another thing, that drove me crazy for a while is that it is not possible to use the .index properties to reference the nodes because the index property is parent based, so for example for the following tree :
-A
–B
—C
-D
A,B,C all have their index property = 0
each first child of a node has an index of 0.
Any ideas, comment MOST welcome
Thank you SO much. It was the DragDropEffects that I was missing.
I really appreciate it. I will let you know how it turns out.
-Paul
The only problem I ran into was with the drop event. If I Dragged and Dropped onto the same object by accident it would lock up my max and I would have to end the Max process so I added a check to see if the Drop Item was the same as the Drag Item.
on tvAX DragDrop arg do
(
pos=tvAX.PointToClient tvAX.MousePosition
DropNode=tvAX.GetNodeAt pos
if dragNode != dropNode do
(
dragNode.remove() -- need to remove the node from the tree
dropNode.Nodes.add dragNode -- add it to the dropNode children
)
tvAX.ExpandALL()
)
I really appreciate the post. I was so stuck.
-Paul
Yes, I ran into this as well…
I didn’t post the complete stuff…
I think you should do the check in the dragover handler rather than
in the Dragdrop, this way the cursor changes to reflect it is not possible to drop there.
glad it helped
Can I smell onion in here ?
Well, it’s all done. TheOnion can be found on my website.
I ended up getting it to work so that…
[ol]
[li]You could not drag a node onto itself[/li][li]You could not drag a parent node onto a child node (group onto a layer)[/li][li]When you dropped a node it would replace the item you you are dropping onto and shift it and the others below it down.[/li][li]When you dropped a child node onto a parent node it is added as the last node for that parent.[/li][/ol]It actually did not take that long once I was started in the right direction. Thanks again Zbuffer.
-Paul
Sorry to get here a little late.
If you look at the selections sets macro that shipped with 3dsMax 9, you will see how I implemented drag and drop for the .NET treeview thingy that is part of the dialog.
Chris J.
P.S.
!! Congrats on porting the Onion !!
Thanks but I got it all figured out. I just posted a new version that solves a small issue when you execute the rename of a layer.
The fix is at my site.
I will be starting on a new layer manager next week. I have to say I like having the access to the .NET stuff in maxscript.
-Paul