Back to Devexpress

GridViewBase.AddingNewRowCommand Property

wpf-devexpress-dot-xpf-dot-grid-dot-gridviewbase-2c4b3a7d.md

latest4.0 KB
Original Source

GridViewBase.AddingNewRowCommand Property

Gets or sets a command that is executed before a new row is added to the GridControl.

Namespace : DevExpress.Xpf.Grid

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

NuGet Package : DevExpress.Wpf.Grid.Core

Declaration

csharp
public ICommand<NewRowArgs> AddingNewRowCommand { get; set; }
vb
Public Property AddingNewRowCommand As ICommand(Of NewRowArgs)

Property Value

TypeDescription
ICommand<NewRowArgs>

A command that is executed before a new row is added to the GridControl.

|

Remarks

Bind a command to the AddingNewRowCommand property to maintain a clean MVVM pattern. The command works like an AddingNewRow event handler and allows you to specify a new data record in a View Model.

A command bound to the AddingNewRowCommand property is executed before the GridControl adds a new record to your data source. In this command, you can specify a data object and initialize its values.

View Example: How to Initialize the New Item Row with Default Values

xaml
<dxg:GridControl>
    <dxg:GridControl.View>
        <dxg:TableView NewItemRowPosition="Top" 
                       AddingNewRowCommand="{Binding AddingNewRowCommand}"/>
    </dxg:GridControl.View>
</dxg:GridControl>
csharp
[Command]
public void AddingNewRow(NewRowArgs args) {
    args.Item = new Product(selectedCompany) {
        ProductName = "", 
        CompanyName = "New Company", 
        UnitPrice = 10, 
        Discontinued = false 
    };
}
vb
<Command>
Public Sub AddingNewRow(ByVal args As NewRowArgs)
    args.Item = New Product(selectedCompany) With {
        .ProductName = "",
        .CompanyName = "New Company",
        .UnitPrice = 10,
        .Discontinued = False
    }
End Sub

Note

The AddingNewRowCommand property does not call the bound command when you add a new row directly to a bound data source.

Refer to the following topic for information on how to add a new row to the GridControl: New Item Row.

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

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-initialize-new-item-row-with-default-values/CS/NewItemRow_MVVM/MainWindow.xaml#L18

xml
NewItemRowPosition="Top"
AddingNewRowCommand="{Binding AddingNewRowCommand}"
ValidateRowCommand="{Binding ValidateRowCommand}"

See Also

AddingNewRow

GridViewBase Class

GridViewBase Members

DevExpress.Xpf.Grid Namespace