Skip to main content
All docs
V24.2

GridViewBase.InvalidRowExceptionCommand Property

Gets or sets a command that is executed when a row fails validation or cannot be saved to a data source.

Namespace: DevExpress.Xpf.Grid

Assembly: DevExpress.Xpf.Grid.v24.2.dll

NuGet Package: DevExpress.Wpf.Grid.Core

Declaration

public ICommand<InvalidRowExceptionArgs> InvalidRowExceptionCommand { get; set; }

Property Value

Type Description
ICommand<InvalidRowExceptionArgs>

A command that is executed when a row fails validation.

Remarks

Bind a command to the InvalidRowExceptionCommand property to maintain a clean MVVM pattern. The command works like an InvalidRowException event handler and allows you to specify an error presentation in a View Model.

Create a command and bind it to the GridViewBase.ValidateRowCommand property to validate entered values. After this command is processed, the GridControl executes a command bound to the InvalidRowExceptionCommand property and allows you to specify how to display validation errors.

Use the InvalidRowExceptionArgs.ExceptionMode property to specify which action to perform when a user enters an invalid value. You can display a message box with an error description, suppress an action, throw an exception, or ignore the validation result.

Refer to the following help topic for more information: Row Validation.

Example

The following example verifies data and does not allow users to move focus to another row until invalid values are corrected:

DevExpress WPF | Grid Control - Invalid Row Exception

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;
        }
    }

The following code snippets (auto-collected from DevExpress Examples) contain references to the InvalidRowExceptionCommand 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.

See Also