TableView.AddNewRow() Method

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

Namespace: DevExpress.Xpf.Grid

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

Declaration

public void AddNewRow()
Public Sub 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.

See Also