The example given below uses the OnContextMenuItemClick and NodeEdit events in conjunction with client-side script to enable the requested functionality.
The result is:
After clicking the context menu item with text Create of a random TreeView Node, a Node with text default will be added as last root Node in the TreeView structure and will be in edit mode. The changes in the text made by the user are reflected in the NodeEdit event handler. Review the code snippet below for further details:
JavaScript
functionHighlightNode(value){var tree =$find("<%= RadTreeView1.ClientID %>");var node = tree.findNodeByValue(value);if(node !=null){
node.startEdit();}}
C#
privatevoidAddNode(RadTreeViewContextMenuEventArgs e){RadTreeNode newNode =newRadTreeNode();
newNode.Value = System.Guid.NewGuid().ToString();
newNode.Text ="default";
newNode.AllowEdit =true;
RadTreeView1.Nodes.Add(newNode);string strScript ="Sys.Application.add_load(function(){ HighlightNode(\""+ newNode.Value +"\")})";
ScriptManager.RegisterStartupScript(typeof(string),"ScriptKey", strScript,true);//if you are using RadAjaxManager, the above two lines should be replaced with://string script = "HighlightNode(\"" + newNode.Value+ "\")";//this.RadAjaxManager.ResponseScripts.Add(script);}protectedvoidRadTreeView1_ContextMenuItemClick(object sender,RadTreeViewContextMenuEventArgs e){if(e.MenuItem.Text =="Create"){AddNode(e);}}protectedvoidRadTreeView1_NodeEdit(object sender,RadTreeNodeEditEventArgs e){RadTreeNode edited = e.Node;
edited.Text = e.Text.ToString();}
VB.NET
PrivateSub AddNode(ByVal e As RadTreeViewContextMenuEventArgs)Dim newNode AsNew RadTreeNode()
newNode.Value =System.Guid.NewGuid().ToString()
newNode.Text="default"
newNode.AllowEdit =True
RadTreeView1.Nodes.Add(newNode)Dim strScript AsString="Sys.Application.add_load(function(){ HighlightNode("""+ newNode.Value +""")})"
ScriptManager.RegisterStartupScript(GetType(String),"ScriptKey", strScript,True)'if you are using RadAjaxManager, the above two lines should be replaced with:'string script = "HighlightNode(\"" + newNode.Value+ "\")";'this.RadAjaxManager.ResponseScripts.Add(script);EndSubProtectedSub RadTreeView1_ContextMenuItemClick(ByVal sender AsObject,ByVal e As RadTreeViewContextMenuEventArgs)If e.MenuItem.Text="Create"Then
AddNode(e)EndIfEndSubProtectedSub RadTreeView1_NodeEdit(ByVal sender AsObject,ByVal e As RadTreeNodeEditEventArgs)Dim edited As RadTreeNode = e.Node
edited.Text= e.Text.ToString()EndSub