Back to Devexpress

GridRowValidationEventArgs.UpdateRowResult Property

wpf-devexpress-dot-xpf-dot-grid-dot-gridrowvalidationeventargs-c0a7742f.md

latest6.4 KB
Original Source

GridRowValidationEventArgs.UpdateRowResult Property

Gets or sets a task that allows you to asynchronously post changes to an underlying data source (database).

Namespace : DevExpress.Xpf.Grid

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

NuGet Package : DevExpress.Wpf.Grid.Core

Declaration

csharp
public Task UpdateRowResult { get; set; }
vb
Public Property UpdateRowResult As Task

Property Value

TypeDescription
Task

A task that allows you to asynchronously post changes to an underlying data source (database).

|

Remarks

Run Demo: Virtual Sources - Editing

  1. Set the ColumnBase.AllowEditing property to true for the columns that end users can edit.

  2. Set the TableView.ShowUpdateRowButtons property to OnCellEditorOpen / OnCellValueChange to enable Edit Entire Row mode.

  3. Handle the GridViewBase.ValidateRow event and set the UpdateRowResult property to a task that asynchronously saves the changes to an underlying data source (database).

xaml
<dxg:GridControl x:Name="grid">
    <dxg:GridControl.Columns>
        <dxg:GridColumn FieldName="Subject" IsSmart="True" AllowEditing="true"/>
        <dxg:GridColumn FieldName="User" IsSmart="True" AllowEditing="true"/>
        <dxg:GridColumn FieldName="Created" IsSmart="True" AllowEditing="true"/>
        <dxg:GridColumn FieldName="Votes" IsSmart="True" AllowEditing="true"/>
        <dxg:GridColumn FieldName="Priority" IsSmart="True" AllowEditing="true"/>
    </dxg:GridControl.Columns>
    <dxg:GridControl.View>
        <dxg:TableView ValidateRow="TableView_ValidateRow" ShowUpdateRowButtons="OnCellValueChange" />
    </dxg:GridControl.View>
</dxg:GridControl>
csharp
private void TableView_ValidateRow(object sender, GridRowValidationEventArgs e) {    
    e.UpdateRowResult = Task.Run(() => {      
        IssuesService.UpdateRow(e.Row as IssueData);
    });
}
vb
Private Sub TableView_ValidateRow(ByVal sender As Object, ByVal e As GridRowValidationEventArgs)
    e.UpdateRowResult = Task.Run(Function()
        IssuesService.UpdateRow(TryCast(e.Row, IssueData))
    End Function)
End Sub

Use the ValidationEventArgs.IsValid property to specify whether a row’s values are valid. Use the ValidationEventArgs.ErrorType and ValidationEventArgs.ErrorContent properties to display an error message.

csharp
private void TableView_ValidateRow(object sender, GridRowValidationEventArgs e) {    
    e.UpdateRowResult = Task.Run(() => {      
        if (!IssuesService.ServerIsConnected) {
            e.IsValid = false;
            e.ErrorContent = "Server is disconnected.";
            e.ErrorType = DevExpress.XtraEditors.DXErrorProvider.ErrorType.Critical;
            return;
        }
        IssuesService.UpdateRow(e.Row as IssueData);
    });
}
vb
Private Sub TableView_ValidateRow(ByVal sender As Object, ByVal e As GridRowValidationEventArgs)
    e.UpdateRowResult = Task.Run(Function()
        If Not IssuesService.ServerIsConnected Then
            e.IsValid = False
            e.ErrorContent = "Server is disconnected."
            e.ErrorType = DevExpress.XtraEditors.DXErrorProvider.ErrorType.Critical
            Return
        End If
        IssuesService.UpdateRow(TryCast(e.Row, IssueData))
    End Function)
End Sub

You can allow users to cancel the Update operation, for example, when they click the Cancel button. To do that, set the GridRowValidationEventArgs.UseCancellationToken property to true and use the GridRowValidationEventArgs.CancellationToken in a cancel function.

csharp
private void On_ValidateRow(object sender, GridRowValidationEventArgs e) {
    // ...
    e.UseCancellationToken = true;
    e.Register(() => DoSomethingToCancelOperation())
    e.ResultAsync = Task.Run(() => {
        // ...
        e.CancellationToken.ThrowIfCancellationRequested();
        // ...
    });
    // ...
}

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the UpdateRowResult 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-bind-to-infiniteasyncsource/CS/InfiniteAsyncSourceSample/MainWindow.xaml.cs#L117

csharp
if(e.IsNewItem) {
    e.UpdateRowResult = IssuesService.AddNewIssueAsync((IssueData)e.Value);
} else {

See Also

GridRowValidationEventArgs Class

GridRowValidationEventArgs Members

DevExpress.Xpf.Grid Namespace