Infragistics(R) NetAdvantage(R) Windows Forms
CellDataErrorEventArgs Class
Members  Example  See Also  E-mail your feedback on this topic.
Infragistics.Win.UltraWinGrid Namespace : CellDataErrorEventArgs Class

Event parameters used for handling data error events

Syntax

Visual Basic (Declaration) 
Public Class CellDataErrorEventArgs 
   Inherits System.EventArgs
C# 
public class CellDataErrorEventArgs : System.EventArgs 

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.

Visual BasicCopy Code
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
C#Copy Code
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;
	}

}

See Also