Xceed Grid for WinForms v4.3 Documentation
ValidationError events

Welcome to Xceed Grid for WinForms v4.3 > Basic Concepts > Events > ValidationError events

The ValidationError events are raised by the AddNew or EndEdit methods when the value of a cell or one of the cells in a DataRow or InsertionRow does not pass the validation process. 

It is suggested that these events be handled since, by default, no exceptions will be thrown by Xceed Grid for WinForms if an invalid value is entered into a cell.

Basic steps - C#

To subscribe to the ValidationError events, the following steps must be performed:

Basic steps - VB.NET

To subscribe to the ValidationError event, the following steps must be performed:

Demonstration

This example assumes that you are in a Windows application and that you are handling the ValidationError event of each cell in the DataRowTemplate (thus for every cell in the grid).

VB.NET
Copy Code
Dim cell As DataCell
For Each cell In GridControl1.DataRowTemplate.Cells
  AddHandler cell.ValidationError, AddressOf Me.cell_ValidationError
Next
Private Sub cell_ValidationError(ByVal sender As Object, ByVal e As CellValidationErrorEventArgs)
   Try
      MessageBox.Show(e.Value.ToString() + " is not a valid value for " + sender.FieldName)
      e.CancelEdit = False
   Catch exception As Exception
      MessageBox.Show( exception.ToString() )
   End Try
End Sub
' If you no longer wish to handle the ValidationError events that are raised,
' you can unsubscribe from the event notification by doing the following:
RemoveHandler cell.ValidationError, AddressOf Me.cell_ValidationError
C#
Copy Code
foreach( DataCell cell in gridControl1.DataRowTemplates.Cells )
{
   cell.ValidationError += new ValidationErrorEventHandler( this.cell_ValidationError );
}
private void cell_ValidationError( object sender, CellValidationErrorEventArgs e )
{
   try
   {
      MessageBox.Show( e.Value.ToString() + " is not a valid value for " + 
                       ( ( DataCell )sender ).FieldName );
      e.CancelEdit = false;
   }
   catch( Exception exception )
   {
      MessageBox.Show( exception.ToString() );
   }
}
// If you no longer wish to handle the ValidationError events that are raised,
// you can unsubscribe from the event notification by doing the following:
cell.ValidationError -= new ValidationErrorEventHandler( this.cell_ValidationError );