GridViewBase.ValidateRowCommand Property
Gets or sets a command that validates row values.
Namespace: DevExpress.Xpf.Grid
Assembly: DevExpress.Xpf.Grid.v24.2.dll
NuGet Package: DevExpress.Wpf.Grid.Core
Declaration
Property Value
Type | Description |
---|---|
ICommand<RowValidationArgs> | A command that validates row values. |
Remarks
Bind a command to the ValidateRowCommand
property to maintain a clean MVVM pattern. The command works like a ValidateRow event handler and allows you to process the row validate operation in a View Model.
The GridControl executes a command bound to the ValidateRowCommand property when the control saves changes to a data source. The save changes process starts when a user focuses another row, or you call the DataViewBase.CommitEditing method.
The Item property returns a data item within the processed row.
The following example verifies if data meet the validation criteria. Use the Result property to specify the validation message.
<dxg:GridControl ItemsSource="{Binding TaskList}" AutoGenerateColumns="AddNew">
<dxg:GridControl.View>
<dxg:TableView AutoWidth="True"
ValidateRowCommand="{Binding ValidateRowCommand}"
InvalidRowExceptionCommand="{Binding InvalidRowCommand}"/>
</dxg:GridControl.View>
</dxg:GridControl>
using DevExpress.Mvvm;
using DevExpress.Mvvm.DataAnnotations;
using DevExpress.Mvvm.Xpf;
// ...
public class MainViewModel : ViewModelBase {
// ...
[Command]
public void ValidateRow(RowValidationArgs args) {
args.Result = GetValidationErrorInfo((Task)args.Item);
}
static ValidationErrorInfo GetValidationErrorInfo(Task task) {
if(task.StartDate > task.EndDate)
return new ValidationErrorInfo("Start Date must be less than End Date");
if(string.IsNullOrEmpty(task.TaskName))
return new ValidationErrorInfo("Enter a task name");
return null;
}
[Command]
public void InvalidRow(InvalidRowExceptionArgs args) {
args.ExceptionMode = ExceptionMode.NoAction;
}
}
Refer to the following topic for more information: Row Validation.
Use the ResultAsync property to validate row data asynchronously.
CRUD Operations
You can implement CRUD operations (create, read update, delete). These operations allow users to manage data in the Data Grid. Refer to the following topic for more information: Implement CRUD Operations in a Data-Bound Grid.
Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the ValidateRowCommand 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.