Skip to content

DevExpress-Examples/winforms-grid-initialize-new-item-row-on-start-editing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WinForms Data Grid - Initialize a new row after the user activates the grid cell

This example handles the InitNewRow event to initialize the New Item Row with default values. The GridView raises the InitNewRow event after the user has changed the value of a cell. The example also handles the GridView.ShownEditor event to force the InitNewRow event to fire after the user has clicked the "Item New Row" cell:

private void gridView1_InitNewRow(object sender, DevExpress.XtraGrid.Views.Grid.InitNewRowEventArgs e) {
    GridView view = sender as GridView;
    view.SetRowCellValue(e.RowHandle, view.Columns["Name"], "Noname");
    view.SetRowCellValue(e.RowHandle, view.Columns["Date"], DateTime.Today);
}
private void gridView1_ShownEditor(object sender, EventArgs e) {
    GridView view = sender as GridView;
    if (view.IsNewItemRow(view.FocusedRowHandle) && view.FocusedColumn.FieldName != "ID")
        view.ActiveEditor.IsModified = true;
}

Files to Review

Documentation