TableView.AddNewRow() Method
Adds a new row to the TableView‘s underlying datasource.
Namespace: DevExpress.Xpf.Grid
Assembly: DevExpress.Xpf.Grid.v20.2.dll
NuGet Packages: DevExpress.WindowsDesktop.Wpf.Grid.Core, DevExpress.Wpf.Grid.Core
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.