wpf-devexpress-dot-xpf-dot-grid-5e1551e7.md
Provides data for the TableView.InitNewRow event.
Namespace : DevExpress.Xpf.Grid
Assembly : DevExpress.Xpf.Grid.v25.2.dll
NuGet Package : DevExpress.Wpf.Grid.Core
public class InitNewRowEventArgs :
RoutedEventArgs
Public Class InitNewRowEventArgs
Inherits RoutedEventArgs
InitNewRowEventArgs is the data class for the following events:
When a user starts to edit the New Item Row, the GridControl raises the TableView.InitNewRow event. You can handle this event to initialize fields within the new record. For example, you can assign a unique value to the key field or assign default field values.
Refer to the following help topic for more information: Add and Remove Rows.
This example demonstrates how to initialize cells displayed within the New Item Row with default values.
<dxg:GridControl x:Name="grid"
AutoGenerateColumns="AddNew">
<dxg:GridControl.View>
<dxg:TableView x:Name="view"
AutoWidth="True"
NewItemRowPosition="Top"
InitNewRow="OnInitNewRow"
ValidateRow="OnValidateRow"
InvalidRowException="OnInvalidRowException" />
</dxg:GridControl.View>
</dxg:GridControl>
void OnInitNewRow(object sender, InitNewRowEventArgs e) {
grid.SetCellValue(e.RowHandle, "UnitPrice", 10);
grid.SetCellValue(e.RowHandle, "CompanyName", "newcompany");
grid.SetCellValue(e.RowHandle, "Discontinued", false);
}
void OnValidateRow(object sender, GridRowValidationEventArgs e) {
if(e.RowHandle == GridControl.NewItemRowHandle) {
e.IsValid = !string.IsNullOrEmpty(((Product)e.Row).ProductName);
e.Handled = true;
}
}
void OnInvalidRowException(object sender, InvalidRowExceptionEventArgs e) {
if(e.RowHandle == GridControl.NewItemRowHandle) {
e.ErrorText = "Please enter the Product Name.";
e.WindowCaption = "Input Error";
}
}
Private Sub OnInitNewRow(ByVal sender As Object, ByVal e As InitNewRowEventArgs)
Me.grid.SetCellValue(e.RowHandle, "UnitPrice", 10)
Me.grid.SetCellValue(e.RowHandle, "CompanyName", "newcompany")
Me.grid.SetCellValue(e.RowHandle, "Discontinued", False)
End Sub
Private Sub OnValidateRow(ByVal sender As Object, ByVal e As GridRowValidationEventArgs)
If e.RowHandle = DataControlBase.NewItemRowHandle Then
e.IsValid = Not String.IsNullOrEmpty(CType(e.Row, Product).ProductName)
e.Handled = True
End If
End Sub
Private Sub OnInvalidRowException(ByVal sender As Object, ByVal e As InvalidRowExceptionEventArgs)
If e.RowHandle = DataControlBase.NewItemRowHandle Then
e.ErrorText = "Please enter the Product Name."
e.WindowCaption = "Input Error"
End If
End Sub
Object EventArgs RoutedEventArgs InitNewRowEventArgs
See Also