wpf-devexpress-dot-xpf-dot-grid-dot-treelistview-546b08a4.md
Occurs before a new node is added to the GridControl and allows you to initialize the new record.
Namespace : DevExpress.Xpf.Grid
Assembly : DevExpress.Xpf.Grid.v25.2.dll
NuGet Package : DevExpress.Wpf.Grid.Core
public event TreeListAddingNewEventHandler AddingNewNode
Public Event AddingNewNode As TreeListAddingNewEventHandler
The AddingNewNode event's data class is TreeListAddingNewEventArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| NewObject | Gets or sets the object to be added to the binding list. Inherited from AddingNewEventArgs. |
| ParentNode | A parent node. |
The AddingNewNode event occurs before the GridControl adds a new record to your data source. In this event handler, you can specify a data object and initialize its values.
<dxg:GridControl>
<dxg:GridControl.View>
<dxg:TableView x:Name="view"
KeyFieldName="ID"
ParentFieldName="ParentID"
NewItemRowPosition="Top"
AddingNewNode="view_AddingNewNode"/>
</dxg:GridControl.View>
</dxg:GridControl>
void view_AddingNewNode(object sender, DevExpress.Xpf.Grid.TreeList.TreeListAddingNewEventArgs e) {
e.NewObject = new Employee() {
ID = view.TotalNodesCount + 1,
Name = "",
Department = "Finance",
Position = "Manager"
};
}
Private Sub view_AddingNewNode(ByVal sender As Object, ByVal e As DevExpress.Xpf.Grid.TreeList.TreeListAddingNewEventArgs)
e.NewObject = New Employee() With {
.ID = view.TotalNodesCount + 1,
.Name = "",
.Department = "Finance",
.Position = "Manager"
}
End Sub
Note
The AddingNewNode event does not fire when you add a new node directly to a bound data source.
If you want to maintain a clean MVVM pattern and specify a new data record in a View Model, create a command and bind it to the AddingNewNodeCommand property.
Refer to the following help topic for more information: Add and Remove Rows.
See Also