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
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.
Tip
Topic: Add and Remove Rows
To Add Rows
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.
Tip
Command: TableViewCommands.AddNewRow
<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>
Use the DataControlBase.NewItemRowHandle to get the new row and set its values.
Tip
Topic: Obtain and Set Cell 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.
Tip
GitHub Example: How to Add and Remove Rows in Code
Related GitHub Examples
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.