Step 5: Enable Data Edit Operations
This step describes how to allow users to edit data.
Note
This tutorial uses the Issues Service as a sample data source.
Allow Users to Edit Data
Set the ColumnBase.AllowEditing property to true for the columns that users can edit.
Set the TableView.ShowUpdateRowButtons property to OnCellEditorOpen / OnCellValueChange to enable Edit Entire Row mode.
Create a task that uses the Issues Service‘s UpdateRowAsync method to save changes to the data source.
Create an UpdateIssue command in the ViewModel. To save changes asynchronously, assign the task to the RowValidationArgs.ResultAsync property.
Bind the command to the GridViewBase.ValidateRowCommand property.
<dxg:GridControl>
<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 ShowUpdateRowButtons="OnCellEditorOpen"
ValidateRowCommand="{Binding UpdateIssueCommand}"/>
</dxg:GridControl.View>
</dxg:GridControl>
[Command]
public void UpdateIssue(RowValidationArgs args) {
args.ResultAsync = UpdateIssueAsync((IssueData)args.Item);
}
static async Task<ValidationErrorInfo> UpdateIssueAsync(IssueData issue) {
await IssuesService.UpdateRowAsync(issue);
return null;
}
Continue or Review
- Proceed to the next tutorial - How to Bind to a Custom Service with Restrictions.
- Review Step 4 - Display Summaries.