Notifications
Clear all

[Closed] DotNet TreeView LabelEdit

Hi guys,

I have been unable to solve this dilemma for ages, and have finally am trying to tackle it head on instead of doing lame workarounds…

What I really want to be able to do is to directly adjust the name of a treeview node by double clicking on it. In order to start editing a label you have to make sure that the treeview labels are editable. If the treeview is called “tv” then this can be done using:



on tv NodeMouseDoubleClick arg do
	(	
	tv.LabelEdit = true
	tv.selectednode.BeginEdit()
	)-- End fo DoubleClick



This event nicely enables the label editing and then begins the edit on the selected node in the treeview. This is a great start, but unfortunately that is all that is good about it. The user can then easily type the new string that they want, but pressing “enter” does not submit the completed string and end the editing… You can use:



tv.selectednode.endEdit true
tv.LabelEdit = false


to safely stop the editing on the selected node and then deactivating label editing on the treeview. Unforunately I can find no way of getting max to hear these commands… I have tried a few event handlers, by looking at names, and trying to understand snippets of other peoples comments around similar troubles:



on tv KeyDown args do (........)

on tv KeyUp args do (...........)

--There is also 

on tv Enter args do (...........)


Unfortunately, here I am not sure how to use or control these… and I dont seem to be getting any response from the treeview when I try… Is this because it is in a labeledit mode? Has the treeview lost focus or something? Sadly this is a very vague area for me!

There also seems to be another handler that could be of use:



on tv AfterLabelEdit args do (........)


I thought I was onto a winner here, but I dont think I am getting it to respond, because I dont think the editing is actually terminating! Cause pressing “enter/return” is not confirming the string in after I have used “tv.selectednode.BeginEdit()”

Does anyone know how to get a press of the “enter/return” key to finish the editing mode, and submit the string to the name of the selected treeview node?

Other people have met this problem before, but unfortunately solutions are being posted in visual basic and C, both of which I am struggling to follow… Here is an example of someone finding a solution that I cannot understand!

Problem posed at:

http://forums.cgsociety.org/showthread.php?t=567817

The solution is offered at:

http://forums.autodesk.com/t5/NET/TreeView-label-edit-in-a-palette/m-p/1415739

If anyone could can understand this dilema and translate out a solution for me, then that would be amazing. I hvae had a bit of success with XML, treeviews, and listviews largely inspired by Paul Neale’s very kind tutorials on his website ( http://www.paulneale.com/index.htm# )

Unfortunately, this has got me stumped though… Thanks for your time everyone

Rich

10 Replies
 lo1

I haven’t tried this with treeview, but I believe you can catch an ‘enter’ press with the KeyUp event (but not the keydown!)

Hey lo,

Thanks for the response! Your line of thought has pushed me slightly in the correct direction, but sadly still no banana. I have tested the following event handlers with some very simple code :



on Tv keyup args do
	(
	print ("keyup args: " + args as string)
	)

on Tv Enter args do
	(
	print ("Enter args: " + args as string)
	)

on Tv keydown args do
	(
	print ("keydown args: " + args as string)
	)

on Tv keypressed args do
	(
	print ("keypressed args: " + args as string)
	)



These are the results:

The on “keypressed” and “Enter” event handlers do nothing and no string is printed at all, when you are working with the treeview in focus or otherwise.

The on “keydown” event handler responds with a string when nearly all keys on the keyboard are pressed, but it doesnt respond when the “Return” key is being pressed!

As you cunningly spotted the on “keyup” event handler responds with a string when nearly all keys are pressed INCLUDING “Return”.

However the sad news is that as soon as the tv.selectednode.BeginEdit() method is called then all of the above event handlers fail to respond until the editing of the text has completed and user has awkwardly clicked away from the node being edited. Pressing “Return” whilst editing the name (in order to hopefully submit the name) fails to trigger any of the event handlers making it impossible to end the editing process! So I am still stuck

Is the treeview losing focus when the tv.selectednode.BeginEdit() method is being called? I am finding this most confusing…

If you have any more ideas then I would love to hear them, because I really need to get over this hurdle fairly soon if possible!

Thanks for your time everyone

Rich

 lo1

I don’t have much experience with editing treeview nodes, but as an emergency last option, I would just fake it with another TextBox control, that I would move to the location of the node being edited, and not use the treenodes editing function.

Have you tried using a “real” dotnetobject Treeview? And connectiong the event handlers to their corresponding functions?

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

what do you mean by “real” TreeView? The dotnetobject instead of dotnetcontrol? I doesn’t matter at all. The problem is – when the tree view goes into Edit label mode the control opens new EditControl, and focus changes to that control. All key events happens for edit control. the parent tree view doesn’t hear child’s key events if it was not ask so.
after holidays (next week) i will show a sample how to solve the problem in mxs using c#…

Hi Guys,

Lo: Your suggestion is exactly the plug that I am going to have to resort too in a minute! It feels a little hacky though, although I admit it doesnt compromise the functionality too much…

Kamelon: Sorry I am not sure what you mean by a real dotnetobject Treeview. I am pretty new to all this implementation of dotnet stuff through Maxscript so I may being more than a little dumb. Check out the Code below… It is a little example that might help people understand where I am trying to head…



 

rollout treeViewRollout "Treevie Label Edit Fail...." width:380 height:470
(

groupBox grp2 "Project Layout" pos:[4,4] width:344 height:448


--Treeview for Project Layout Design
dotNetControl tv "system.windows.forms.treeView" pos:[10,20] width:328 height:424

--Function to knock up a quick Tree
fn CreateQuickTree theTV NoElements NoChildren =
	(
	
	--Recursive function to Populate TreeViews
	for i=0 to (NoElements - 1) do 
		(
		TreeBranchName = "Leaf_0_" + i as string
		TreeBranch = dotNetObject "System.Windows.Forms.TreeNode" TreeBranchName
			
		for d=1 to NoChildren do 
			(
			LeafName = "Leaf_1_" + d as string
			Leaf = dotNetObject "System.Windows.Forms.TreeNode" LeafName
			
			TreeBranch.nodes.add Leaf
			)--End of For
		
		theTV.nodes.add TreeBranch
		)--End of for			

	)--End of RecurseTreeHierarchy 


--Double click event handler to begin Label Edit
on tv NodeMouseDoubleClick arg do
	(
	local node = tv.GetNodeAt arg.X arg.Y;
	
	if (node != undefined) AND (node.level != 0) then
		(
		tv.LabelEdit = true
		tv.selectednode.BeginEdit()
		)	

	)-- End fo DoubleClick

/*
NOW lets lay out some event Handlers that print out to the script editor when the are called. Try clicking in the treeview and you will see some of the event handlers work
However none of the the event handlers work when we are in the the label edit mode, after we have called tv.selectednode.BeginEdit(). Since no handlers work then I cannot capture
the "Return" key press, and I cannot terminate the editing stage!! 

Try it out and see! 

Double click on a tree Node to start editing the label. From there no key press can exit the label editing 
and no event handler can capture a key press (like a "Return" Key press" EEEEk! Now I am Stuck in Label edit world forever! 

*/

on tv keyup args do
	(
	print ("KEYUP Event Handler has been Triggered!")
	)

on tv Enter args do
	(
	print ("ENTER Event Handler has been Triggered!")
	)

on tv keydown args do
	(
	print ("KEYDOWN Event Handler has been Triggered!")
	)

on tv keypressed args do
	(
	print ("KEYPRESSED Event Handler has been Triggered!")
	)




on treeViewRollout open do
	(
	CreateQuickTree tv 4 2
	)--treeViewRollout
	
)-- End of ROLLOUT



if try(treeViewRollout.indialog)catch(false) then (destroydialog treeViewRollout)
createdialog treeViewRollout


Anyone who wants to try this is a complete little example that you can run by just copying and pasting into the script editor.

First click in the treeview with a single left mouse click to get the focus. Then hit some different keys on the keyboard. This will cause some of the event handlers to trigger, which kicks out some little print outs to the script editor…

Note that when you press “Return” only one of the event handlers triggers (good spot lo!)

Now try double clicking on a tree node. This will activate the tv.selectednode.BeginEdit() function, which will start the label edit. Now look as you type in the name the key event handlers no longer trigger, which gives me no way of catching an “Return” press. This leaves me stuck in Edit mode! Help!

Note guys, that this is not a complete example, it does not include an attempt to call the End Edit function and to turn the tv.leveledit = false, because there is no where I can put them where I can trigger them!

Hope this helps explain the dilema…

Thanks again for taking the time to look at this guys. It is really appreciated…

Cheers,

Rich

Yeah, I meant the dotnetobject instead of the dotnetcontrol, since there are some bugs in event handling with the dotnetcontrol that might solved the issue, but I’ve searched for a while and saw that the fix wouldnt be that simple like Denis said.

Hi Guys,

Thanks so much for the description about this. Denis, your breakdown makes it very clear what is actually going on, which explains much of my frustrations over these last weeks.

If you do get the chance to share a sample solution with us then I will be eternally grateful, since this is a feature that I am really keen to implement, and with things wondering into C# then I am starting to get out of my depth as regards things I can fix myself.

It is very kind of you to take the time to do so. In the meantime I hope you enjoy the rest of your holidays!

Thanks everyone for pitching in with your help

Rich

http://forums.cgsociety.org/showpost.php?p=6785100&postcount=1

Hi Denis,

Thank you so much for sharing this example. In no way would I have ever arrived at this solution. I will be working through this in the next few days in order to try and understand a little of what you have done. But this really allows me to move forward with my current tool design, which is a huge relief.

Thanks again for sharing and explaining. It is really appreciated

Rich