A newer version of this page is available. Switch to the current version.

Add and Remove Rows

  • 3 minutes to read

New Item Row

End users can use the New Item Row to add new records:

NewItemRowPositions

Demo: New Item Row

To show the New Item Row, set the TableView.NewItemRowPosition property to NewItemRowPosition.Top or NewItemRowPosition.Bottom.

End users can cancel appending a new row by pressing the Esc key while the row is focused. If a cell is in edit mode, an end user should press the Esc key twice.

The new row is automatically added to the data source and a blank new item row is displayed if the row’s data is valid and focus has been moved to another row.

NOTE

The TreeList View does not currently support a UI for adding new nodes.

The following properties allow you to customize New Item Row:

Property Description
ColumnBase.NewItemRowCellStyle Specifies a style for the column’s cell displayed within the New Item Row.
TableView.NewItemRowCellStyle Specifies a common style for all data cells displayed within the New Item Row.
NOTE

You can apply the NewItemRowCellStyle only to the data cells of the New Item Row displayed at the top of the TableView, i.e., the TableView.NewItemRowPosition property is set to NewItemRowPosition.Top.

Add and Remove Rows In Code

Add New Rows

Method Description
TableView.AddNewRow Adds a new row to the TableView‘s underlying datasource.
TreeListView.AddNewNode Adds a new node to the TreeListView‘s underlying datasource.

These methods add a blank row to the view’s datasource. If the New Item Row is enabled, these methods move focus to this element. Otherwise, the new record is temporarily placed below the existing records. After an end user has entered cell values and the row has been accepted, the new row moves to its final location according to the current filtering, grouping and sorting settings.

Initialize New Rows

Event Description
GridViewBase.AddingNewRow Occurs before adding a new row to a data grid and allows you to initialize the new record.
TreeListView.AddingNewNode Occurs before adding a new node to a data grid and allows you to initialize the new record.
TableView.InitNewRow Allows you to initialize a new row with default values.
TreeListView.InitNewNode Allows you to initialize a new node with default values.

Using these events you can initialize the required fields within the new record. Refer to the Obtain and Set Cell Values topic for information on how to set cell values.

Remove Rows

Method Description
GridViewBase.DeleteRow Deletes the specified data row.

The data row is identified by its handle - a non negative integer value. Refer to Obtaining Row Handles for information on how to obtain row handles.

See Also