Occurs when an error condition arises in the control.
The event handler receives an argument of type ErrorEventArgs containing data related to this event. The following ErrorEventArgs properties provide information specific to this event.
Property | Description |
---|
Cancel (Inherited from System.ComponentModel.CancelEventArgs) | |
DataErrorInfo | If this error event was fired due to a data error, this will return the DataErrorInfo instance associated with it. Otherwise it will return null. |
ErrorText | Gets or sets the error text. This is the text that will be displayed in the error dialog box. You can modify this property to change what is displayed in the error dialog box. To prevent the error dialog box from displaying, set the Cancel to true. |
ErrorType | Indicates what type of error occurred that prompted this Error event to be fired. |
MaskErrorInfo | If this error event was fired due to a mask error, this will return the MaskErrorInfo instance associated with it. Otherwise it will return null. |
MultiCellOperationErrorInfo | This object contains information on the error that occurred during a multi-cell operation. |
Following code shows some of the information available in Error event. The UltraGrid fires Error event when there is an error. There are three types of Error events. You can check which type this instance is by looking at the ErrorType property off the passed in ErrorEventArgs parameter. If the error type is Data, then the error occured while trying to commit the user input into a cell. The underlying data source can throw an exception when updating a cell or a row with new user input for example, when the user inputs a value that can't be converted to the underlying column's data type or when the input doesn't satisfy underlyng database constraints. If the error type of Mask, then there was some mask related event.
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
Imports System.Diagnostics
Private Sub UltraGrid1_Error(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.ErrorEventArgs) Handles ultraGrid1.Error
If e.ErrorType = ErrorType.Data Then
' DataErroInfo object contains details regarding the data error.
' ErrorText property contains the error message.
Debug.WriteLine("Data Error: Error text = " & e.DataErrorInfo.ErrorText)
' Exception property will contain the exception that caused the Error event to fire.
' It will be null if there was no exception.
If Not Nothing Is e.DataErrorInfo.Exception Then
Debug.WriteLine("Data Error: Exception type = " & e.DataErrorInfo.Exception.GetType().Name)
Else
Debug.WriteLine("Data Error: No Exception.")
End If
' Cell returns the cell involved in the data error. It will be null for errors generated
' when performing operations like adding or deleting rows or operations that do not
' deal with a cell.
If Not Nothing Is e.DataErrorInfo.Cell Then
Debug.WriteLine("DataError: Cell's column key = " & e.DataErrorInfo.Cell.Column.Key)
Else
Debug.WriteLine("DataError: No cell.")
End If
' Row returns the row involved in the data error. It will be null if error occurred while
' doing an operation that did not involve a row.
If Not Nothing Is e.DataErrorInfo.Row Then
Debug.WriteLine("DataError: Index of the row involved = " & e.DataErrorInfo.Row.Index)
Else
Debug.WriteLine("DataError: No row.")
End If
' Source property indicates how the data error was generated.
Debug.Write("DataError: Source of the error is ")
Select Case (e.DataErrorInfo.Source)
Case DataErrorSource.CellUpdate
If Nothing Is e.DataErrorInfo.InvalidValue Then
Debug.WriteLine("Cell updating.")
Else
Debug.WriteLine("Cell updating with invalid value of " & e.DataErrorInfo.InvalidValue.ToString())
End If
Case DataErrorSource.RowAdd
Debug.WriteLine("Row adding.")
Case DataErrorSource.RowDelete
Debug.WriteLine("Row deleting.")
Case DataErrorSource.RowUpdate
Debug.WriteLine("Row updating.")
Case DataErrorSource.Unspecified
Debug.WriteLine("Unknown.")
End Select
' Set the cancel to true to prevent the grid from displaying a message for
' this error. Instead we will display our own message box below.
e.Cancel = True
MessageBox.Show(Me, _
"Please enter a valid value for the cell." & vbCrLf & "Data error defatils:" & e.ErrorText, _
"Invalid input", _
MessageBoxButtons.OK, _
MessageBoxIcon.Error)
ElseIf e.ErrorType = ErrorType.Mask Then
' MaskErroInfo property contains the detaisl regarding the mask error.
' InvalidText is the text in the cell that doesn't satisfy the mask input.
Debug.WriteLine("Mask Error: Invalid text = " & e.MaskErrorInfo.InvalidText)
' StartPos may indicate the position in the text that caused the mask input
' verification failed.
Debug.WriteLine("Mask Error: Character position = " & e.MaskErrorInfo.StartPos)
' Prevent the UltraGrid from beeping whenever the user types in a
' character that doesn't match the mask as well as for other mask
' related errors.
e.MaskErrorInfo.CancelBeep = True
Else
' Set the cancel to true to prevent the grid from displaying the message
' for this error.
e.Cancel = True
Debug.WriteLine("Unknown error occured with the error message of: " & e.ErrorText)
End If
End Sub
using Infragistics.Shared;
using Infragistics.Win;
using Infragistics.Win.UltraWinGrid;
using System.Diagnostics;
private void ultraGrid1_Error(object sender, Infragistics.Win.UltraWinGrid.ErrorEventArgs e)
{
if ( e.ErrorType == ErrorType.Data )
{
// DataErroInfo object contains details regarding the data error.
// ErrorText property contains the error message.
Debug.WriteLine( "Data Error: Error text = " + e.DataErrorInfo.ErrorText );
// Exception property will contain the exception that caused the Error event to fire.
// It will be null if there was no exception.
if ( null != e.DataErrorInfo.Exception )
Debug.WriteLine( "Data Error: Exception type = " + e.DataErrorInfo.Exception.GetType( ).Name );
else
Debug.WriteLine( "Data Error: No Exception." );
// Cell returns the cell involved in the data error. It will be null for errors generated
// when performing operations like adding or deleting rows or operations that do not
// deal with a cell.
if ( null != e.DataErrorInfo.Cell )
Debug.WriteLine( "DataError: Cell's column key = " + e.DataErrorInfo.Cell.Column.Key );
else
Debug.WriteLine( "DataError: No cell." );
// Row returns the row involved in the data error. It will be null if error occurred while
// doing an operation that did not involve a row.
if ( null != e.DataErrorInfo.Row )
Debug.WriteLine( "DataError: Index of the row involved = " + e.DataErrorInfo.Row.Index );
else
Debug.WriteLine( "DataError: No row." );
// Source property indicates how the data error was generated.
Debug.Write( "DataError: Source of the error is " );
switch ( e.DataErrorInfo.Source )
{
case DataErrorSource.CellUpdate:
if ( null == e.DataErrorInfo.InvalidValue )
Debug.WriteLine( "Cell updating." );
else
Debug.WriteLine( "Cell updating with invalid value of " + e.DataErrorInfo.InvalidValue.ToString( ) );
break;
case DataErrorSource.RowAdd:
Debug.WriteLine( "Row adding." );
break;
case DataErrorSource.RowDelete:
Debug.WriteLine( "Row deleting." );
break;
case DataErrorSource.RowUpdate:
Debug.WriteLine( "Row updating." );
break;
case DataErrorSource.Unspecified:
Debug.WriteLine( "Unknown." );
break;
}
// Set the cancel to true to prevent the grid from displaying a message for
// this error. Instead we will display our own message box below.
e.Cancel = true;
MessageBox.Show( this,
"Please enter a valid value for the cell.\nData error defatils:" + e.ErrorText,
"Invalid input",
MessageBoxButtons.OK,
MessageBoxIcon.Error );
}
else if ( e.ErrorType == ErrorType.Mask )
{
// MaskErroInfo property contains the detaisl regarding the mask error.
// InvalidText is the text in the cell that doesn't satisfy the mask input.
Debug.WriteLine( "Mask Error: Invalid text = " + e.MaskErrorInfo.InvalidText );
// StartPos may indicate the position in the text that caused the mask input
// verification failed.
Debug.WriteLine( "Mask Error: Character position = " + e.MaskErrorInfo.StartPos );
// Prevent the UltraGrid from beeping whenever the user types in a
// character that doesn't match the mask as well as for other mask
// related errors.
e.MaskErrorInfo.CancelBeep = true;
}
else
{
// Set the cancel to true to prevent the grid from displaying the message
// for this error.
e.Cancel = true;
Debug.WriteLine( "Unknown error occured with the error message of: " + e.ErrorText );
}
}
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