Node Editing in TreeView Control
2 Mar 202513 minutes to read
The TreeView allows you to edit nodes by setting the allowEditing property to true. To directly edit the nodes in place, double-click the TreeView node or select the node and press the F2 key.
When editing is completed by focus out or by pressing the Enter key, the modified node’s text saves automatically. If you do not want to save the modified node’s text in the TreeView node, press the Escape key. It does not save the edited text to the TreeView node.
-
Node editing can also be performed programmatically by using the
beginEditmethod. When passing the node ID or element through this method, an edit textbox will be created for the particular node, allowing it to be edited. -
If you need to validate or prevent editing, the
nodeEditingevent can be used which is triggered before the TreeView node is renamed. On successfully renaming a node thenodeEditedevent will be triggered.
In the following example, the first level node’s text cannot be changed, but all other level nodes’ text can be changed.
<ejs-treeview id="treedata" allowEditing="true">
<e-treeview-fields dataSource="ViewBag.dataSource" id="id" parentId="pid" text="name" hasChildren="hasChild" expanded="expanded" selected="is_selected"></e-treeview-fields>
</ejs-treeview>The output will look like the image below: