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. 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" that when true does not persist user changes.
The sample code below shows how to start editing using the API:
Copy[C#]
radTreeView1.AllowEdit = true;
radTreeView1.SelectedNode = radTreeView1.Nodes[0];
radTreeView1.BeginEdit();
Copy[VB.NET]
RadTreeView1.AllowEdit = True
RadTreeView1.SelectedNode = RadTreeView1.Nodes(0)
RadTreeView1.BeginEdit()
The Editing Lifecycle
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 in RadTreeView 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.
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 to the node Text property.
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.
Custom Editors
At present the RadTreeView uses only the text box editor for editing node Text properties. When an editor is invoked the EditorRequired event fires allowing the editor implementation to be replaced by a custom instance.