Back to Devexpress

TreeListView.AddingNewNode Event

wpf-devexpress-dot-xpf-dot-grid-dot-treelistview-546b08a4.md

latest3.4 KB
Original Source

TreeListView.AddingNewNode Event

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

Declaration

csharp
public event TreeListAddingNewEventHandler AddingNewNode
vb
Public Event AddingNewNode As TreeListAddingNewEventHandler

Event Data

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

PropertyDescription
NewObjectGets or sets the object to be added to the binding list. Inherited from AddingNewEventArgs.
ParentNodeA parent node.

Remarks

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.

xaml
<dxg:GridControl>
    <dxg:GridControl.View>
        <dxg:TableView x:Name="view"
                       KeyFieldName="ID" 
                       ParentFieldName="ParentID"
                       NewItemRowPosition="Top"
                       AddingNewNode="view_AddingNewNode"/>
    </dxg:GridControl.View>
</dxg:GridControl>
csharp
void view_AddingNewNode(object sender, DevExpress.Xpf.Grid.TreeList.TreeListAddingNewEventArgs e) {
    e.NewObject = new Employee() {
        ID = view.TotalNodesCount + 1,
        Name = "",
        Department = "Finance",
        Position = "Manager"
    };
}
vb
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

GridViewBase.AddingNewRow

TreeListView Class

TreeListView Members

DevExpress.Xpf.Grid Namespace