Edit this page

Editing

RadDiagram gives you the ability to edit the content of its items. You can double-click items in order to edit them or use RadDiagramCommand.

Enable/Disable Editing

By default, the RadDiagramItems are enabled for editing. In order to disable this functionality, you can use the IsEditable property:

Fig1. IsEditable

diagram-items-manipulation-editing 001


this.radDiagram1.IsEditable = true;

Me.RadDiagram1.IsEditable = True

Start Editing By Using Keyboard

Once the edit behavior is enabled, you can start the editing process by selecting the item and pressing the F2 key.

Controlling Editing in Code Behind

In order to start/end editing a RadDiagramItem, you can set IsInEditMode property to true/false.

RadDiagramItem also provides four editing events:

  • PreviewBeginEdit: fires when a RadDiagramItem is about to be edited. It is cancelable.

  • BeginEdit: fires when a RadDiagramItem has just entered in edit mode.
    In the code snippet below it is demonstrated how to access the editor element:

Access editor element

private void shape_BeginEdit(object sender, EventArgs e)
{
    RadDiagramShape shape = sender as RadDiagramShape;
    RadTextBoxControlElement editorElement = shape.FindDescendant<RadTextBoxControlElement>();
}

Private Sub shape_BeginEdit(sender As Object, e As EventArgs)
    Dim shape As RadDiagramShape = TryCast(sender, RadDiagramShape)
    Dim editorElement As RadTextBoxControlElement = shape.FindDescendant(Of RadTextBoxControlElement)()
End Sub

  • PreviewEndEdit: fires when a RadDiagramItem is about to leave the edit mode. It is cancelable.

  • EndEdit: fires when a RadDiagramItem has just left the edit mode.

Edit using Commands

RadDiagram provides three predefined commands for editing the selected item - BeginEdit, CommitEdit and CancelEdit.

Fig2. Editing by commands

diagram-items-manipulation-editing 002


private void radButtonEdit_Click(object sender, EventArgs e)
{
    this.radDiagram1.DiagramElement.TryExecuteCommand(Telerik.WinControls.UI.Diagrams.DiagramCommands.BeginEdit);
}

private void radButtonConfirm_Click(object sender, EventArgs e)
{
    this.radDiagram1.DiagramElement.TryExecuteCommand(Telerik.WinControls.UI.Diagrams.DiagramCommands.CommitEdit);
}

private void radButtonCancel_Click(object sender, EventArgs e)
{
    this.radDiagram1.DiagramElement.TryExecuteCommand(Telerik.WinControls.UI.Diagrams.DiagramCommands.CancelEdit);
}

Private Sub RadButtonEdit_Click(sender As Object, e As EventArgs) Handles RadButtonEdit.Click
    Me.RadDiagram1.DiagramElement.TryExecuteCommand(Telerik.WinControls.UI.Diagrams.DiagramCommands.BeginEdit)
End Sub
Private Sub RadButtonConfirm_Click(sender As Object, e As EventArgs) Handles RadButtonConfirm.Click
    Me.RadDiagram1.DiagramElement.TryExecuteCommand(Telerik.WinControls.UI.Diagrams.DiagramCommands.CommitEdit)
End Sub
Private Sub RadButtonCancel_Click(sender As Object, e As EventArgs) Handles RadButtonCancel.Click
    Me.RadDiagram1.DiagramElement.TryExecuteCommand(Telerik.WinControls.UI.Diagrams.DiagramCommands.CancelEdit)
End Sub