A newer version of this page is available. Switch to the current version.

GridViewBase.ValidateRow Event

Allows you to specify whether the focused row’s data is valid, and whether the row can lose focus.

Namespace: DevExpress.Xpf.Grid

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


public event GridRowValidationEventHandler ValidateRow

Event Data

The ValidateRow event's data class is GridRowValidationEventArgs. The following properties provide information specific to this event:

Property Description
CancellationToken Gets an object that notifies that the Update operation should be canceled.
Culture Gets the culture related to the validation. Inherited from ValidationEventArgs.
ErrorContent Gets or sets an object that describes the validation error. Inherited from ValidationEventArgs.
ErrorType Gets or sets the error icon type. Inherited from ValidationEventArgs.
Handled Gets or sets a value that indicates the present state of the event handling for a routed event as it travels the route. Inherited from RoutedEventArgs.
IsValid Gets or sets a value specifying whether the value is valid. Inherited from ValidationEventArgs.
OriginalSource Gets the original reporting source as determined by pure hit testing, before any possible Source adjustment by a parent class. Inherited from RoutedEventArgs.
RoutedEvent Gets or sets the RoutedEvent associated with this RoutedEventArgs instance. Inherited from RoutedEventArgs.
Row Gets the processed row.
RowHandle Gets the processed row’s handle.
Source Gets or sets a reference to the object that raised the event. Inherited from RoutedEventArgs.
UpdateRowResult Gets or sets a task that allows you to asynchronously post changes to an underlying data source (database).
UpdateSource Gets the action that caused the validation. Inherited from ValidationEventArgs.
UseCancellationToken Gets or sets whether the Update operation can be canceled.
Value Gets the editor’s value. Inherited from ValidationEventArgs.

The event data class exposes the following methods:

Method Description
InvokeEventHandler(Delegate, Object) When overridden in a derived class, provides a way to invoke event handlers in a type-specific way, which can increase efficiency over the base implementation. Inherited from RoutedEventArgs.
OnSetSource(Object) When overridden in a derived class, provides a notification callback entry point whenever the value of the Source property of an instance changes. Inherited from RoutedEventArgs.
SetError(Object) Marks the processed input value as invalid and displays an error within the editor. Inherited from ValidationEventArgs.
SetError(Object, ErrorType) Marks the processed input value as invalid and displays an error within the editor with the specified error icon type. Inherited from ValidationEventArgs.


Row validation is performed within the ValidateRow event handler. This event is fired after the focused row’s data has been modified and it is about to lose focus. To manually force row validation, call the DataViewBase.CommitEditing method.

The GridRowValidationEventArgs.Row property returns the processed row. The GridRowValidationEventArgs.RowHandle property returns the row’s handle. After cell values are obtained, you can verify whether these values meet your validity criteria. If the row fails validation, set the event’s IsValid parameter to false. Otherwise, leave the IsValid parameter set to true.

To learn more, see Row Validation.


This example shows how to check the validity of data entered by end users into a data row. The GridViewBase.ValidateRow and GridViewBase.InvalidRowException events are handled to validate the focused row’s data, and if it is invalid, prevent the row focus from being moved to another row until invalid values are corrected.

Since the Task class does not support error notifications, it implements the IDXDataErrorInfo interface, providing two members to get error descriptions for the entire row and for individual cells (data source fields). This displays error icons within cells with invalid values. Pointing to such an error icon displays a tooltip with an error description.

View Example

<Window x:Class="DXGrid_ValidateRow.Window1" 
    Title="Window1" Height="300" Width="500">
        <dxg:GridControl x:Name="grid">
                <dxg:GridColumn FieldName="TaskName" />
                <dxg:GridColumn FieldName="StartDate" />
                <dxg:GridColumn FieldName="EndDate" />
                <dxg:TableView AutoWidth="True" 
                               InvalidRowException="TableView_InvalidRowException" />
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;
using DevExpress.Xpf.Grid;
using DevExpress.XtraEditors.DXErrorProvider;

namespace DXGrid_ValidateRow {
    public partial class Window1 : Window {
        public Window1() {
            grid.ItemsSource = TaskList.GetData();

        private void TableView_ValidateRow(object sender, GridRowValidationEventArgs e) {
            DateTime startDate = ((Task)e.Row).StartDate;
            DateTime endDate = ((Task)e.Row).EndDate;
            e.IsValid = startDate < endDate;

        private void TableView_InvalidRowException(object sender, InvalidRowExceptionEventArgs e) {
            e.ExceptionMode = ExceptionMode.NoAction;

    public class TaskList {
        public static List<Task> GetData() {
            List<Task> data = new List<Task>();
            data.Add(new Task() { TaskName = "Complete Project A",
                StartDate = new DateTime(2009, 7, 17), EndDate = new DateTime(2009, 7, 10) });
            data.Add(new Task() { TaskName = "Test Website",
                StartDate = new DateTime(2009, 7, 10), EndDate = new DateTime(2009, 7, 12) });
            data.Add(new Task() { TaskName = "Publish Docs",
                StartDate = new DateTime(2009, 7, 4), EndDate = new DateTime(2009, 7, 6) });
            return data;

    public class Task : IDXDataErrorInfo {
        public string TaskName { get; set; }
        public DateTime StartDate { get; set; }
        public DateTime EndDate { get; set; }
        void IDXDataErrorInfo.GetError(ErrorInfo info) {
            if (StartDate > EndDate) {
                    "Either StartDate or EndDate should be corrected.",
        void IDXDataErrorInfo.GetPropertyError(string propertyName, ErrorInfo info) {
            switch (propertyName) {
                case "StartDate":
                    if (StartDate > EndDate)
                            "StartDate must be less than EndDate",
                case "EndDate":
                    if (StartDate > EndDate)
                            "EndDate must be greater than StartDate",
                case "TaskName":
                    if (IsStringEmpty(TaskName))
                            "Task name hasn't been entered",
        void SetErrorInfo(ErrorInfo info, string errorText, ErrorType errorType) {
            info.ErrorText = errorText;
            info.ErrorType = errorType;
        bool IsStringEmpty(string str) {
            return (str != null && str.Trim().Length == 0);
See Also