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; } }