Skip to main content
A newer version of this page is available.
All docs
V19.1

TableView.AddNewRow() Method

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

Namespace: DevExpress.Xpf.Grid

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

Declaration

public void AddNewRow()

Remarks

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:GridControl.View>
            <dxg:TableView x:Name="view"/>
        </dxg:GridControl.View>
    </dxg:GridControl>
    <!-- -->
    <Button Click="addNewRow">Add a New Row</Button> 
    
    void addNewRow(object sender, RoutedEventArgs e) {
        view.AddNewRow();
    }
    
  2. Use the DataControlBase.NewItemRowHandle to get the new row and set its values.

    void addNewRow(object sender, RoutedEventArgs e) {
        view.AddNewRow();
        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.

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the AddNewRow() method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also