Back to Devexpress

TreeListView.NodeEditStarting Event

wpf-devexpress-dot-xpf-dot-grid-dot-treelistview-1696aab1.md

latest8.1 KB
Original Source

TreeListView.NodeEditStarting Event

Occurs when a user starts to edit a node.

Namespace : DevExpress.Xpf.Grid

Assembly : DevExpress.Xpf.Grid.v25.2.dll

NuGet Package : DevExpress.Wpf.Grid.Core

Declaration

csharp
public event EventHandler<TreeListNodeEditStartingEventArgs> NodeEditStarting
vb
Public Event NodeEditStarting As EventHandler(Of TreeListNodeEditStartingEventArgs)

Event Data

The NodeEditStarting event's data class is TreeListNodeEditStartingEventArgs. The following properties provide information specific to this event:

PropertyDescription
CancelGets or sets whether to cancel the start of the edit operation.
CellEditorsGets an array of the CellEditorData objects that allow you to specify settings in the Edit Form.
HandledGets or sets a value that indicates the present state of the event handling for a routed event as it travels the route. Inherited from RoutedEventArgs.
NodeGets the processed node. Inherited from TreeListNodeEventArgs.
OriginalSourceGets the original reporting source as determined by pure hit testing, before any possible Source adjustment by a parent class. Inherited from RoutedEventArgs.
RoutedEventGets or sets the RoutedEvent associated with this RoutedEventArgs instance. Inherited from RoutedEventArgs.
RowGets the processed row. Inherited from TreeListNodeEventArgs.
SourceGets or sets a reference to the object that raised the event. Inherited from RoutedEventArgs.

The event data class exposes the following methods:

MethodDescription
InvokeEventHandler(Delegate, Object)When overridden in a derived class, provides a way to invoke event handlers in a type-specific way, which can increase efficiency over the base implementation. Inherited from RoutedEventArgs.
OnSetSource(Object)When overridden in a derived class, provides a notification callback entry point whenever the value of the Source property of an instance changes. Inherited from RoutedEventArgs.

Remarks

Handle this event to get information about the node that the user starts to edit. If you want to maintain a clean MVVM pattern and process the start of the edit operation in a View Model, create a command and bind it to the NodeEditStartingCommand property.

Set the Cancel property to true to suppress the node edit operation. The moment when NodeEditStarting occurs depends on the GridControl‘s edit mode.

Edit Form

If you process data edit operations in the Edit Form, the event occurs when a user opens the form.

The TreeListNodeEditStartingEventArgs class contains the CellEditors property that returns an array of CellEditorData objects. Each object allows you to specify editor’s settings. When users start to edit a node, you may want to initialize values or make certain editors read-only. To do that, specify the corresponding CellEditorData.Value property or set the CellEditorData.ReadOnly property to true.

The following code sample specifies settings for the node that contains information about employees. For example, you can initialize the ID editor (CellEditors[0] in code) and disable the Department editor (CellEditors[4]) for new nodes.

cs
private void OnNodeEditStarting(object sender, TreeListNodeEditStartingEventArgs e) {
    if (e.Node == null) { // is the New Item Row
        e.CellEditors[0].Value = grid.VisibleRowCount + 1;
        e.CellEditors[4].ReadOnly = true;

    } else {
        e.CellEditors[0].ReadOnly = true;
        e.CellEditors[4].ReadOnly = false;
    }
}
vb
Private Sub OnNodeEditStarting(ByVal sender As Object, ByVal e As TreeListNodeEditStartingEventArgs)
    If e.Node Is Nothing Then ' is the New Item Row
        e.CellEditors(0).Value = grid.VisibleRowCount + 1
        e.CellEditors(4).[ReadOnly] = True
    Else
        e.CellEditors(0).[ReadOnly] = True
        e.CellEditors(4).[ReadOnly] = False
    End If
End Sub

View Example: Data Grid for WPF - How to Specify Edit Form Settings

In-place Editors and Edit Entire Row

The NodeEditStarting event occurs when a user opens an editor in a node for the first time. The View does not activate all editors, and you cannot use the CellEditors property to specify their settings.

See Also

NodeEditStartingCommand

NodeEditStarted

NodeEditFinished

TreeListView Class

TreeListView Members

DevExpress.Xpf.Grid Namespace