Editing Nodes
By default RadTreeView does not allow node editing. If the AllowEditing property is set to true, the user may select a node and press F2 to initiate editing. By default a text editor is invoked and allows the editing of the node label. When the edit process ends the entered value is assigned to the node Text property, or the field specified by the ValueMember property. If the user cancels editing by pressing Escape the value is not persisted. Editing can also be initiated and canceled programmatically.
Use the BeginEdit() method to initiate editing on the selected node
Use the EndEdit() method to conclude editing. EndEdit() takes a single boolean parameter "cancelEdit", if this parameter is set to true the changes are not persisted.
The sample code below shows how to start editing using the API:
radTreeView1.AllowEdit = true;
// set the SelectedNode - this node will be edited
radTreeView1.SelectedNode = radTreeView1.Nodes[0];
// this will start edit on selected node
radTreeView1.BeginEdit();
RadTreeView1.AllowEdit = True
' set the SelectedNode - this node will be edited
RadTreeView1.SelectedNode = RadTreeView1.Nodes(0)
' this will start edit on selected node
RadTreeView1.BeginEdit()
The Editing Lifecycle
1. A node enters edit mode
A node that is being displayed by the RadTreeView control is selected and the user presses the F2 key to bring the node into edit mode.
The RadTreeView control calls the BeginEdit() method and a new editor instance is initialized. It is available publicly through the ActiveEditor property and is associated with the node that is about to be edited.
The editor fires its Editing event, which in turn triggers the firing of the RadTreeView Editing event. If either event is canceled, no further action takes place.
A text box based editor appears for input.
2. A node is brought out of edit mode
The editor determines if it wants to handle the keystroke.
The editor instance performs the action it has defined for the Enter key. Typically this indicates that edit mode should be exited and any changes made during the edit session should be applied.
In response to the action described in the previous step the EndEdit() method is called and the ValueChanged event is fired.
The RadTreeView fires the ValueValidating event which allows the user to hook up custom logic for verification. If the ValueValidating event does not succeed (e.Cancel is true), ValidationError event is fired to notify all listeners that the validation has failed.
The RadTreeView control sets the node Text property to the string representation of the editor Value property.
EditMode
By default, when RadTreeView is in unbound mode, modifying the Text or the Value of a node will automatically update the other one. This behavior can be controlled via the EditMode property of the TreeViewElement.
The property has the following values:
Value: When the user performs edit, the Value will be edited.
Text: When the user performs edit, the Text will be edited.
TextAndValue: When the user performs edit, both the Text and the Value will be changed.
When EditMode is set to TextAndValue , editing either of the properties programmatically will result in changing both of them.