TableView.AddNewRow() Method

Adds a new row to the TableView‘s underlying datasource.

Namespace: DevExpress.Xpf.Grid

Assembly: DevExpress.Xpf.Grid.v21.1.dll


public void AddNewRow()


Use the AddNewRow method to add a new row to the view’s underlying datasource. The View immediately reflects any changes made to the datasource and focuses the new record.

When a new record is added, the datasource may initialize some values (key fields, for instance). Record initialization can also be performed manually by handling the TableView.InitNewRow event.

An end user can add new records via the New Item Row.

To Add Rows

  1. Call the AddNewRow method to add a new row.

    If the New Item Row is enabled, these methods move focus to this element. Otherwise, they temporarily add an empty row at the bottom.

    <dxg:GridControl x:Name="grid" AutoGenerateColumns="AddNew" ItemsSource="{Binding PersonList}">
            <dxg:TableView x:Name="view"/>
    <!-- -->
    <Button Click="addNewRow">Add a New Row</Button> 
    void addNewRow(object sender, RoutedEventArgs e) {
  2. Use the DataControlBase.NewItemRowHandle to get the new row and set its values.

    void addNewRow(object sender, RoutedEventArgs e) {
        int newRowHandle = DataControlBase.NewItemRowHandle;
        grid.SetCellValue(newRowHandle, "ProductName", "New Product");
        grid.SetCellValue(newRowHandle, "CompanyName", "New Company");
        grid.SetCellValue(newRowHandle, "UnitPrice", 10);            
        grid.SetCellValue(newRowHandle, "Discontinued", false);

After values are set and accepted, the new row moves according to the current filter, group, and sort settings.

View Example: How to Add and Remove Rows in Code

See Also