Skip to main content

TreeListView.InitNewNode Event

Allows you to initialize a new node with default values.

Namespace: DevExpress.Xpf.Grid

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

NuGet Package: DevExpress.Wpf.Grid.Core

Declaration

public event TreeListNodeEventHandler InitNewNode

Event Data

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

Property Description
Handled Gets 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.
Node Gets the processed node.
OriginalSource Gets the original reporting source as determined by pure hit testing, before any possible Source adjustment by a parent class. Inherited from RoutedEventArgs.
RoutedEvent Gets or sets the RoutedEvent associated with this RoutedEventArgs instance. Inherited from RoutedEventArgs.
Row Gets the processed row.
Source Gets or sets a reference to the object that raised the event. Inherited from RoutedEventArgs.

The event data class exposes the following methods:

Method Description
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

Note

We recommend that you use the AddingNewNode event instead to initialize a new node with default values.

The GridControl raises the InitNewNode event in the following cases:

This event occurs after the GridControl adds a new record to your data source. Handle the InitNewNode event to initialize fields in the new record. For example, you can assign a unique value to the key field or assign default field values. To do this, use the GridControl.SetCellValue method.

If the TreeListView is in Self-Referential mode, you cannot add the New Item Row with the duplicated primary key. Handle the InitNewNode event and initialize a field specified in the TreeListView.KeyFieldName property with a unique primary key.

<dxg:TreeListView x:Name="view" 
                  KeyFieldName="ID" 
                  ParentFieldName="ParentID" 
                  NewItemRowPosition="Bottom" 
                  InitNewNode="OnInitNewNode" /> 
void OnInitNewNode(object sender, DevExpress.Xpf.Grid.TreeList.TreeListNodeEventArgs e) {
    view.SetNodeValue(e.Node, "ID", view.TotalNodesCount + 1);
    // ...
} 

If you want to maintain a clean MVVM pattern and initialize a new node in a View Model, create a command and bind it to the InitNewNodeCommand property.

Refer to the following help topic for more information: Add and Remove Rows.

See Also