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