[Closed] .Net Treeview questions
Hey,
I followed a few tutorials (mxsHelp, PEN’s page) to get a bit more familiar with dotNet stuff. So, I have a treeview and buttons to add / remove TreeViewNodes. However, when I add a new node, the selection remains as it was before. I’d like to set the selection to the new node. I checked the methods for these elements, but didn’t find anything that worked.
newNode = dnTv.Nodes.add "temp"
newNode.Select() ? (doesnt work)
Furthermore, I’d like to deselect an / all items whenever the user clicks somewhere in the TreeView. (not on a node) But the tv Clicks event somehow only replys when I click on a node.
on dnTv Click arg do (
hitNode = dnTv.GetNodeAt (dotNetObject "System.Drawing.Point" arg.x arg.y)
if hitNode != undefined then print hitNode.tag.value
else print "missed"
)
Context menu works pretty neat already.
I normally use the SelectedNode property for both setting the currently selected item and clearing the selection. So if you create a new node and store it in a variable you can assign that variable to SelectedNode to have it selected. If you set SelectedNode to undefined it will clear the selection.
I’ve tried to add the drag and drop functionality (from LoneRobot’s page) to the treeView, but I have two problems.
[b]#1[/b] - The mouseUp event only responds if called from within the clientRectangle. Releasing the mouse button while being within the rect, returns [i]true [/i]in the listener. However when moving the cursor [u]outside [/u]of the rect and releasing the button, it doesn't work anymore.
I tested it with a button, like in the tutorial and that works just fine...
on dnTv MouseUp sender args do
(
print (sender.clientrectangle.contains args.x args.y)
)
[b]#2[/b] - When you select a node in the TreeView and move the cursor while the mousebutton is still pressed, (drag and drop operation) the TreeView Node selection jumps back to the last selected node. Is there any way to disable that?
2# – Just assign the node under the mouse to the selectedNode property like we talked about before.
As for 1#… well, what kind of drag and drop are you trying to do? Are you trying to drop into the scene?
Yes I try to drag and drop “max files” into the scene. I have stored the filepath in the TreeViewNode tag property. But the event isnt working properly.
When I create a button and assign the mouseUp event to it, it works nicely. It reads the filename from the selected TreeViewNode tag and drag&drops the file in the scene.
You can try with the LostFocus event, which if you are dragging something only happens when you release the mouse button outside, it’s not perfect however and you might have to implement some workarounds.