wpf-devexpress-dot-xpf-dot-grid-dot-gridviewbase-40381a46.md
Gets or sets a command that validates row values.
Namespace : DevExpress.Xpf.Grid
Assembly : DevExpress.Xpf.Grid.v25.2.dll
NuGet Package : DevExpress.Wpf.Grid.Core
public ICommand<RowValidationArgs> ValidateRowCommand { get; set; }
Public Property ValidateRowCommand As ICommand(Of RowValidationArgs)
| Type | Description |
|---|---|
| ICommand<RowValidationArgs> |
A command that validates row values.
|
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.
View Example: How to Validate Data Rows
<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;
}
}
Imports DevExpress.Mvvm
Imports DevExpress.Mvvm.DataAnnotations
Imports DevExpress.Mvvm.Xpf
' ...
Public Class MainViewModel
Inherits ViewModelBase
' ...
<Command>
Public Sub ValidateRow(ByVal args As RowValidationArgs)
args.Result = GetValidationErrorInfo(CType(args.Item, Task))
End Sub
Private Shared Function GetValidationErrorInfo(ByVal task As Task) As ValidationErrorInfo
If task.StartDate > task.EndDate Then Return New ValidationErrorInfo("Start Date must be less than End Date")
If String.IsNullOrEmpty(task.TaskName) Then Return New ValidationErrorInfo("Enter a task name")
Return Nothing
End Function
<Command>
Public Sub InvalidRow(ByVal args As InvalidRowExceptionArgs)
args.ExceptionMode = ExceptionMode.NoAction
End Sub
End Class
Refer to the following topic for more information: Row Validation.
Use the ResultAsync property to validate row data asynchronously.
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.
View Example: How to Implement CRUD Operations in a Data-Bound Grid
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.
wpf-data-grid-implement-crud-operations/CS/ViewModel/EFCore/PagedAsyncSource/MainWindow.xaml#L25
<dxg:GridControl.View>
<dxg:TableView ShowUpdateRowButtons="OnCellEditorOpen" ValidateRowCommand="{Binding ValidateRowCommand}"
ShowFixedTotalSummary="True" DataSourceRefreshCommand="{Binding DataSourceRefreshCommand}" />
wpf-data-grid-extend-crud-operations/CS/AsyncCRUDOperations/MainWindow.xaml#L25
<dxg:GridControl.View>
<dxg:TableView NewItemRowPosition="Top" ShowUpdateRowButtons="OnCellEditorOpen" ValidateRowCommand="{Binding ValidateRowCommand}" ValidateRowDeletionCommand="{Binding ValidateRowDeletionCommand}" DataSourceRefreshCommand="{Binding DataSourceRefreshCommand}" ShowFixedTotalSummary="True" />
</dxg:GridControl.View>
how-to-bind-to-grpc/CS/InfiniteAsyncSource.GRPC/MainWindow.xaml#L57
ShowUpdateRowButtons="OnCellEditorOpen"
ValidateRowCommand="{Binding UpdateIssueCommand}"/>
</dxg:GridControl.View>
wpf-data-grid-initialize-new-item-row-with-default-values/CS/NewItemRow_MVVM/MainWindow.xaml#L19
AddingNewRowCommand="{Binding AddingNewRowCommand}"
ValidateRowCommand="{Binding ValidateRowCommand}"
InvalidRowExceptionCommand="{Binding InvalidRowCommand}" />
wpf-data-grid-validate-data-rows/CS/ValidateRow_MVVM/MainWindow.xaml#L16
<dxg:TableView AutoWidth="True"
ValidateRowCommand="{Binding ValidateRowCommand}"
InvalidRowExceptionCommand="{Binding InvalidRowCommand}"/>
wpf-data-grid-extend-crud-operations/CS/Undo/UndoCRUDOperationsBehavior.cs#L111
var args = new RowValidationArgs(editingCache, Source.IndexOf(item), false, new CancellationToken(), false);
AssociatedObject.ValidateRowCommand?.Execute(args);
if(!Validate(args.Result)) {
wpf-data-grid-extend-crud-operations/VB/Undo/UndoCRUDOperationsBehavior.vb#L140
Dim args = New RowValidationArgs(editingCache, Source.IndexOf(item), False, New CancellationToken(), False)
AssociatedObject.ValidateRowCommand?.Execute(args)
If Not Validate(args.Result) Then
See Also