Skip to main content
A newer version of this page is available. .
All docs
V22.1

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.v22.1.dll

NuGet Package: DevExpress.Wpf.Grid.Core

Declaration

public ICommand<NewRowArgs> AddingNewRowCommand { get; set; }

Property Value

Type Description
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.

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

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.

See Also