Skip to main content
A newer version of this page is available. .

TreeListView.InitNewNode Event

Allows you to initialize a new node with default values.

Namespace: DevExpress.Xpf.Grid

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

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

You can initialize the New Item Row with default values:

GridViewBase.AddingNewRow / TreeListView.AddingNewNode Event

TableView.InitNewRow / TreeListView.InitNewNode Event

Occurs before a new row is added to the View.

Occurs before a new row is added to the View.

Use this event to create a new row instance.

Use this event to set field values within the New Item Row.

<dxg:GridControl Name="grid">
    <dxg:GridControl.View>
        <dxg:TableView Name="view" 
            NewItemRowPosition="Top" 
            AddingNewRow="view_AddingNewRow" />
    </dxg:GridControl.View>
</dxg:GridControl>
View Model
public class ViewModel {
    public ViewModel() {
        CreateList();
    }
    public ObservableCollection<Person> PersonList
        { get; set; }
    void CreateList() {
        PersonList = new ObservableCollection<Person>();
        for (int i = 0; i < 3; i++) {
            Person p = new Person(i);
            PersonList.Add(p);
        }
    }
}
public class Person {
    public Person(int i) {
        ProductName = "ProductName" + i;
        CompanyName = "CompanyName" + i;
        UnitPrice = i;
        Discontinued = i % 2 == 0;
    }
    public string ProductName { get; set; }
    public string CompanyName { get; set; }
    public int UnitPrice { get; set; }
    public bool Discontinued { get; set; }
} 
void view_AddingNewRow(object sender, 
        AddingNewEventArgs e) {
    e.NewObject = new Person(1);
}
<dxg:GridControl Name="grid">
    <dxg:GridControl.View>
        <dxg:TableView Name="view" 
            NewItemRowPosition="Top" 
            InitNewRow="view_InitNewRow" />
    </dxg:GridControl.View>
</dxg:GridControl>
View Model
public class ViewModel {
    public ViewModel() {
        CreateList();
    }
    public ObservableCollection<Person> PersonList 
        { get; set; }
    void CreateList() {
        PersonList = new ObservableCollection<Person>();
        for (int i = 0; i < 3; i++) {
            Person p = new Person(i);
            PersonList.Add(p);
        }
    }
}
public class Person {
    public Person(int i) {
        ProductName = "ProductName" + i;
        CompanyName = "CompanyName" + i;
        UnitPrice = i;
        Discontinued = i % 2 == 0;
    }
    public string ProductName { get; set; }
    public string CompanyName { get; set; }
    public int UnitPrice { get; set; }
    public bool Discontinued { get; set; }
} 
void view_InitNewRow(object sender, 
        InitNewRowEventArgs e) {
    grid.SetCellValue(e.RowHandle, "CompanyName", "New Company");
    grid.SetCellValue(e.RowHandle, "UnitPrice", 10);
    grid.SetCellValue(e.RowHandle, "Discontinued", false);
}

Note

The GridControl creates a new row instance if the datasource allows you to add new rows and the object provides a constructor without parameters. Otherwise, handle the GridViewBase.AddingNewRow / TreeListView.AddingNewNode event and specify the NewObject property.

Note

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

Code Sample
<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);
    // ...
} 
See Also