Step 5: Enable Data Edit Operations
You can allow users to edit data in the GridControl.
Explore the full source code in the following example and demo:
#Implementation Details
Enable the ColumnBase.AllowEditing property 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 theViewModel
. To save changes asynchronously, assign the task to theRowValidationArgs.ResultAsync
property.Bind the command to the GridViewBase.ValidateRowCommand.
xml
<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>
C#
[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;
}