Version

CellDataError Event

Occurs after BeforeExitEditMode is fired when the value user has typed is invalid.
Syntax
'Declaration
 
Public Event CellDataError As CellDataErrorEventHandler
public event CellDataErrorEventHandler CellDataError
Event Data

The event handler receives an argument of type CellDataErrorEventArgs containing data related to this event. The following CellDataErrorEventArgs properties provide information specific to this event.

PropertyDescription
ForceExit True if the cell is being forced to exit edit mode. If this is true then StayInEditMode will be ignored.
RaiseErrorEvent Indicates whether to raise Error event. Default value is true.
RestoreOriginalValue Whether to restore the value in the cell to original value. Default value is true.
StayInEditMode Indicates whether to stay in edit mode. Default value is true.
Remarks

CellDataError is fired when the user tries to update the cell with an invalid value. It gets fired after BeforeExitEditMode is fired. If BeforeExitEditMode is cancalled, then this event and successive events related to exiting the edit mode are not fired.

Thie event gets fired either because the value in the editor is invalid, or when setting the value to bound datasource does not succed. If the grid fails to validate the value, then it will fire this event and will not attempt to update the cell with the value. If validations succeds, then the grid will attempt to update the cell, and if that fails, then it will fire this event.

Example
Following code shows some of the information available in CellDataError event and the event's potential uses.

For an overview of how to handle events in Visual Basic or Visual C#, see Event Handlers in Visual Basic and Visual C#. For specific information and code examples illustrating how to consume events in your application, see Consuming Events in the .NET Framework Developer's Guide.

Imports Infragistics.Shared
Imports Infragistics.Win
Imports Infragistics.Win.UltraWinGrid

  Private Sub UltraGrid1_CellDataError(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.CellDataErrorEventArgs) Handles ultraGrid1.CellDataError

      ' CellDataError gets fired when the user attempts to exit the edit mode
      ' after entering an invalid value in the cell. There are several properties
      ' on the passed in event args that you can set to control the UltraGrid's
      ' behaviour.

      ' Typically ForceExit is false. The UltraGrid forces exits on cells under
      ' circumstances like when it's being disposed of. If ForceExit is true, then 
      ' the UltraGrid will ignore StayInEditMode property and exit the cell 
      ' restoring the original value ignoring the value you set to StayInEditMode
      ' property.
      If Not e.ForceExit Then
          ' Default for StayInEditMode is true. However you can set it to false to
          ' cause the grid to exit the edit mode and restore the original value. We
          ' will just leave it true for this example.
          e.StayInEditMode = True

          ' Set the RaiseErrorEvent to false to prevent the grid from raising 
          ' the error event and displaying any message.
          e.RaiseErrorEvent = False

          ' Instead display our own message.
          If Me.ultraGrid1.ActiveCell.Column.DataType Is GetType(DateTime) Then
              MessageBox.Show(Me, "Please enter a valid date.", "Invalid input", MessageBoxButtons.OK, MessageBoxIcon.Error)
          ElseIf Me.ultraGrid1.ActiveCell.Column.DataType Is GetType(Decimal) Then
              MessageBox.Show(Me, "Please enter a valid numer.", "Invalid input", MessageBoxButtons.OK, MessageBoxIcon.Error)
          End If
      Else
          ' Set the RaiseErrorEvent to false to prevent the grid from raising 
          ' the error event.
          e.RaiseErrorEvent = False
      End If

  End Sub
using Infragistics.Shared;
using Infragistics.Win;
using Infragistics.Win.UltraWinGrid;
using System.Diagnostics;

private void ultraGrid1_CellDataError(object sender, Infragistics.Win.UltraWinGrid.CellDataErrorEventArgs e)
{

	// CellDataError gets fired when the user attempts to exit the edit mode
	// after entering an invalid value in the cell. There are several properties
	// on the passed in event args that you can set to control the UltraGrid's
	// behaviour.

	// Typically ForceExit is false. The UltraGrid forces exits on cells under
	// circumstances like when it's being disposed of. If ForceExit is true, then 
	// the UltraGrid will ignore StayInEditMode property and exit the cell 
	// restoring the original value ignoring the value you set to StayInEditMode
	// property.
	if ( !e.ForceExit )
	{
		// Default for StayInEditMode is true. However you can set it to false to
		// cause the grid to exit the edit mode and restore the original value. We
		// will just leave it true for this example.
		e.StayInEditMode = true;
	    
		// Set the RaiseErrorEvent to false to prevent the grid from raising 
		// the error event and displaying any message.
		e.RaiseErrorEvent = false;

		// Instead display our own message.
		if ( this.ultraGrid1.ActiveCell.Column.DataType == typeof( DateTime ) )
		{
			MessageBox.Show( this, "Please enter a valid date.", "Invalid input", MessageBoxButtons.OK, MessageBoxIcon.Error );
		}
		else if ( this.ultraGrid1.ActiveCell.Column.DataType == typeof( decimal ) )
		{
			MessageBox.Show( this, "Please enter a valid numer.", "Invalid input", MessageBoxButtons.OK, MessageBoxIcon.Error );
		}
	}
	else
	{
		// Set the RaiseErrorEvent to false to prevent the grid from raising 
		// the error event.
		e.RaiseErrorEvent = false;
	}

}
Requirements

Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Server 2012, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also