Back to Devexpress

TableView.AddNewRow(Boolean) Method

wpf-devexpress-dot-xpf-dot-grid-dot-tableview-dot-addnewrow-x28-system-dot-boolean-x29.md

latest4.5 KB
Original Source

TableView.AddNewRow(Boolean) Method

Adds a new row to the GridControl‘s data source.

Namespace : DevExpress.Xpf.Grid

Assembly : DevExpress.Xpf.Grid.v25.2.dll

NuGet Package : DevExpress.Wpf.Grid.Core

Declaration

csharp
public void AddNewRow(
    bool showUpdateRowButtons = false
)
vb
Public Sub AddNewRow(
    showUpdateRowButtons As Boolean = False
)

Optional Parameters

NameTypeDefaultDescription
showUpdateRowButtonsBooleanFalse

If the Edit Entire Row mode and the New Item Row are enabled, you can set this parameter to true to allow users edit values in the new row before posting this row to the data source.

|

Remarks

Use the AddNewRow method to add a new row to the grid’s data source. The View reflects changes made in the data source and focuses the new record.

The GridControl does not move focus to the new record if a user focuses the Automatic Filter Row. To avoid this behavior, you can manually focus a data row and call the AddNewRow method (for example, you can use the DataViewBase.MoveLastRow method):

csharp
if (tableView.FocusedRowHandle == DataControlBase.AutoFilterRowHandle)
    tableView.MoveLastRow();
tableView.AddNewRow();
vb
If tableView.FocusedRowHandle = DataControlBase.AutoFilterRowHandle Then 
    tableView.MoveLastRow()
tableView.AddNewRow()

Refer to the following help topic for more information: Add and Remove Rows.

Example

The following example demonstrates how to add a new row to the GridControl and set this row’s values:

View Example: How to Add and Remove Rows in Code

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

  2. Use the DataControlBase.NewItemRowHandle to get the new row and set its values.

  3. 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(Boolean) 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.

wpf-data-grid-add-and-remove-rows-in-code/CS/AddRemoveRows/AddRemoveRowBehavior.cs#L45

csharp
void AddNewRow() {
    AssociatedObject.AddNewRow();
}

wpf-data-grid-add-and-remove-rows-in-code/VB/AddRemoveRows/AddRemoveRowBehavior.vb#L64

vb
Private Sub AddNewRow()
    AssociatedObject.AddNewRow()
End Sub

See Also

TableView Class

TableView Members

DevExpress.Xpf.Grid Namespace