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
Public Event InitNewNode As TreeListNodeEventHandler
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.
|
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.
|
RoutedEvent |
Gets or sets the RoutedEvent associated with this RoutedEventArgs instance.
|
Row |
Gets the processed row.
|
Source |
Gets or sets a reference to the object that raised the event.
|
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.
|
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.
|
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>
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; }
}
Public Class ViewModel
Public Sub New()
CreateList()
End Sub
Public Property PersonList
As ObservableCollection(Of Person)
Private Sub CreateList()
PersonList = New ObservableCollection(Of Person)()
For i As Integer = 0 To 3 - 1
Dim p As Person = New Person(i)
PersonList.Add(p)
Next
End Sub
End Class
Public Class Person
Public Sub New(ByVal i As Integer)
ProductName = "ProductName" & i
CompanyName = "CompanyName" & i
UnitPrice = i
Discontinued = i Mod 2 = 0
End Sub
Public Property ProductName As String
Public Property CompanyName As String
Public Property UnitPrice As Integer
Public Property Discontinued As Boolean
End Class
void view_AddingNewRow(object sender,
AddingNewEventArgs e) {
e.NewObject = new Person(1);
}
Private Sub view_AddingNewRow(ByVal sender As Object,
ByVal e As AddingNewEventArgs)
e.NewObject = New Person(1)
End Sub
|
<dxg:GridControl Name="grid">
<dxg:GridControl.View>
<dxg:TableView Name="view"
NewItemRowPosition="Top"
InitNewRow="view_InitNewRow" />
</dxg:GridControl.View>
</dxg:GridControl>
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; }
}
Public Class ViewModel
Public Sub New()
CreateList()
End Sub
Public Property PersonList
As ObservableCollection(Of Person)
Private Sub CreateList()
PersonList = New ObservableCollection(Of Person)()
For i As Integer = 0 To 3 - 1
Dim p As Person = New Person(i)
PersonList.Add(p)
Next
End Sub
End Class
Public Class Person
Public Sub New(ByVal i As Integer)
ProductName = "ProductName" & i
CompanyName = "CompanyName" & i
UnitPrice = i
Discontinued = i Mod 2 = 0
End Sub
Public Property ProductName As String
Public Property CompanyName As String
Public Property UnitPrice As Integer
Public Property Discontinued As Boolean
End Class
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);
}
Private Sub view_InitNewRow(ByVal sender As Object,
ByVal e As InitNewRowEventArgs)
grid.SetCellValue(e.RowHandle, "CompanyName", "New Company")
grid.SetCellValue(e.RowHandle, "UnitPrice", 10)
grid.SetCellValue(e.RowHandle, "Discontinued", False)
End Sub
|
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.
<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);
// ...
}
Private Sub OnInitNewNode(ByVal sender As Object, ByVal e As DevExpress.Xpf.Grid.TreeList.TreeListNodeEventArgs)
view.SetNodeValue(e.Node, "ID", view.TotalNodesCount + 1)
' ...
End Sub
See Also