windowsforms-devexpress-dot-xtragrid-dot-views-dot-grid-a59c4817.md
Provides data for the ColumnView.InitNewRow event.
Namespace : DevExpress.XtraGrid.Views.Grid
Assembly : DevExpress.XtraGrid.v25.2.dll
NuGet Packages : DevExpress.Win.Grid, DevExpress.Win.Navigation
public class InitNewRowEventArgs :
EventArgs
Public Class InitNewRowEventArgs
Inherits EventArgs
InitNewRowEventArgs is the data class for the following events:
The ColumnView.InitNewRow event is raised when a new row is added to a View. The InitNewRowEventArgs class provides the InitNewRowEventArgs.RowHandle property that identifies the handle of the added row.
InitNewRowEventArgs objects with proper settings are automatically created and passed to ColumnView.InitNewRow event handlers.
The following example demonstrates how to handle the ColumnView.InitNewRow event to initialize the “ID” and “CreateDate” fields (cells) of a new data row.
using System;
using System.Data;
using DevExpress.XtraGrid.Views.Grid;
namespace DXApplication9 {
public partial class Form1 : DevExpress.XtraEditors.XtraForm {
public Form1() {
InitializeComponent();
gridControl1.DataSource = InitDataTable();
Load += Form1_Load;
buttonAddNewOrder.Click += ButtonAddNewOrder_Click;
gridView1.InitNewRow += GridView1_InitNewRow;
// Displays the New Item Row within the Grid View.
gridView1.OptionsView.NewItemRowPosition = NewItemRowPosition.Bottom;
}
private void ButtonAddNewOrder_Click(object sender, EventArgs e) {
// Adds a new record to the grid's data source.
gridView1.AddNewRow();
}
private void GridView1_InitNewRow(object sender, InitNewRowEventArgs e) {
GridView view = sender as GridView;
view.SetRowCellValue(e.RowHandle, view.Columns["ID"], Guid.NewGuid());
view.SetRowCellValue(e.RowHandle, view.Columns["CreateDate"], DateTime.Now);
}
private void Form1_Load(object sender, EventArgs e) {
// Makes the ID column read-only. Users cannnot edit its values.
gridView1.Columns["ID"].OptionsColumn.ReadOnly = true;
}
DataTable InitDataTable() {
DataTable table = new DataTable("DataRecords");
table.Columns.AddRange(new DataColumn[] {
new DataColumn("ID", typeof(Guid)),
new DataColumn("CreateDate", typeof(DateTime)),
new DataColumn("Customer Name", typeof(string))
});
table.Rows.Add(new object[] { Guid.NewGuid(), new DateTime(2024, 1, 1, 9, 44, 12), "Silva" });
table.Rows.Add(new object[] { Guid.NewGuid(), new DateTime(2023, 12, 31, 11, 15, 18), "Mike" });
table.Rows.Add(new object[] { Guid.NewGuid(), new DateTime(2023, 12, 31, 10, 20, 10), "Nathan" });
return table;
}
}
}
Imports System
Imports System.Data
Imports DevExpress.XtraGrid.Views.Grid
Namespace DXApplication9
Partial Public Class Form1
Inherits DevExpress.XtraEditors.XtraForm
Public Sub New()
InitializeComponent()
gridControl1.DataSource = InitDataTable()
AddHandler Load, AddressOf Form1_Load
AddHandler buttonAddNewOrder.Click, AddressOf ButtonAddNewOrder_Click
AddHandler gridView1.InitNewRow, AddressOf GridView1_InitNewRow
' Displays the New Item Row within the Grid View.
gridView1.OptionsView.NewItemRowPosition = NewItemRowPosition.Bottom
End Sub
Private Sub ButtonAddNewOrder_Click(ByVal sender As Object, ByVal e As EventArgs)
' Adds a new record to the grid's data source.
gridView1.AddNewRow()
End Sub
Private Sub GridView1_InitNewRow(ByVal sender As Object, ByVal e As InitNewRowEventArgs)
Dim view As GridView = TryCast(sender, GridView)
view.SetRowCellValue(e.RowHandle, view.Columns("ID"), Guid.NewGuid())
view.SetRowCellValue(e.RowHandle, view.Columns("CreateDate"), Date.Now)
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
' Makes the ID column read-only. Users cannnot edit its values.
gridView1.Columns("ID").OptionsColumn.ReadOnly = True
End Sub
Private Function InitDataTable() As DataTable
Dim table As New DataTable("DataRecords")
table.Columns.AddRange(New DataColumn() {
New DataColumn("ID", GetType(Guid)),
New DataColumn("CreateDate", GetType(Date)),
New DataColumn("Customer Name", GetType(String))
})
table.Rows.Add(New Object() { Guid.NewGuid(), New Date(2024, 1, 1, 9, 44, 12), "Silva" })
table.Rows.Add(New Object() { Guid.NewGuid(), New Date(2023, 12, 31, 11, 15, 18), "Mike" })
table.Rows.Add(New Object() { Guid.NewGuid(), New Date(2023, 12, 31, 10, 20, 10), "Nathan" })
Return table
End Function
End Class
End Namespace
Object EventArgs InitNewRowEventArgs
See Also