Back to Devexpress

New Item Row/Card

windowsforms-1430-controls-and-libraries-data-grid-visual-elements-view-common-elements-new-item-row-card.md

latest5.8 KB
Original Source

New Item Row/Card

  • Jun 13, 2025
  • 3 minutes to read

The new item row/card is used to enter new records. In Grid Views, the new item row can be displayed above or below all data and group rows. In Card Views and Layout Views the new item card is displayed as an empty card below all the cards.

GridView:

CardView:

Tip

New records are added only when a user starts typing cell values in the New Item Row.

The table below lists the main properties that affect an element’s appearance.

|

Appearance

|

The new item row/card uses the data rows and cards display settings.

| |

Row Handle

|

GridControl.NewItemRowHandle

| |

Availability

|

For Grid Views, it is possible to use the GridOptionsView.NewItemRowPosition property to make the new item row always enabled.

In Card Views and Layout Views the new item card is only displayed when a new card is added to the View (via the ColumnView.AddNewRow method or embedded navigator).

If the new item row is hidden in a Grid View, it will be displayed when a new row is added to the View via the ColumnView.AddNewRow method or embedded navigator. In this case, the new item row will be hidden when focus is moved to another row.

| |

Position

|

For Grid Views use the GridOptionsView.NewItemRowPosition property.

| |

Editing

|

You cannot obtain or modify cell values until there is a row object that corresponds to a record. In case of new rows added via the New Item Row, Data Grid initializes new row objects for these rows only after a user modifies any cell.

Do not manually add or remove rows before a new row object is posted into an underlying Grid data source. Data Grid posts new row objects when the New Item Row loses focus, or when the UpdateCurrentRow method is called.

| |

Custom Value Initialization

|

ColumnView.InitNewRow

|

To learn more, see Add and Remove Rows.

Example: Add a New Row by Typing Within the New Item Row

The example adds a new data row to the grid’s data source after the user starts typing within the New Item Row (the behavior inspired by the standard DataGridView).

View Example

Example: Initialize a New Row after the User Activates a 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 ShownEditor event to force the InitNewRow event to fire after the user has clicked the “Item New Row” cell:

csharp
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;
}
vb
Private Sub gridView1_InitNewRow(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Grid.InitNewRowEventArgs)
    Dim view As GridView = TryCast(sender, GridView)
    view.SetRowCellValue(e.RowHandle, view.Columns("Name"), "Noname")
    view.SetRowCellValue(e.RowHandle, view.Columns("Date"), DateTime.Today)
End Sub
Private Sub gridView1_ShownEditor(ByVal sender As Object, ByVal e As EventArgs)
    Dim view As GridView = TryCast(sender, GridView)
    If view.IsNewItemRow(view.FocusedRowHandle) AndAlso view.FocusedColumn.FieldName <> "ID" Then
        view.ActiveEditor.IsModified = True
    End If
End Sub

View Example

See Also

Rows

Appearance and Conditional Formatting

Custom Painting Basics