The event handler receives an argument of type InvalidValueExceptionEventArgs containing data related to this event.
The following
InvalidValueExceptionEventArgs properties provide information specific to this event.
Property |
Description |
ErrorText |
Gets or sets the error description to be displayed in the message box/tooltip. |
Exception |
Gets the exception that caused the event. |
ExceptionMode |
Gets or sets the type of response to supplying invalid values. |
Value |
Gets an invalid value that caused the exception. |
WindowCaption |
Gets or sets the caption of the error message box. |
The InvalidValueException event allows you to handle exceptions raised as the result of assigning invalid values to cells. Generally, this takes place when using a wrong value type or when raising an exception during validation (using the ValidateEditor method). The InvalidValueException event fires regardless of whether the value was entered by the end-user or assigned via code. Write a handler for this event to perform the appropriate exception handling, as shown in the example below. The event parameter provides a number of properties that allow you to access exception information, specify whether the exception should be raised, etc.
For detailed information on how to handle exceptions, see the Validating Editors topic.

Example
The following example prohibits invalid "colBudget" column cell value assignment. The cell value should be grater than zero and less than 1,000,000. The ValidatingEditor event is handled to check the entered value's validity. The InvalidValueException event is handled to display an exception message box if invalid cell value assignment occurs. In this instance, the GridView.HideEditor method is called to discard the changes made and to destroy the cell's editor.
C# |
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Columns;
private void gridView1_ValidatingEditor(object sender, BaseContainerValidateEditorEventArgs e) {
ColumnView view = sender as ColumnView;
GridColumn column = (e as EditFormValidateEditorEventArgs)?.Column ?? view.FocusedColumn;
if (column.Name != "colBudget") return;
if ((Convert.ToInt32(e.Value) < 0) || (Convert.ToInt32(e.Value) > 1000000))
e.Valid = false;
}
private void gridView1_InvalidValueException(object sender, InvalidValueExceptionEventArgs e) {
ColumnView view = sender as ColumnView;
if (view == null) return;
e.ExceptionMode = ExceptionMode.DisplayError;
e.WindowCaption = "Input Error";
e.ErrorText = "The value should be greater than 0 and less than 1,000,000";
view.HideEditor();
}
|
VB |
Imports DevExpress.XtraEditors.Controls
Imports DevExpress.XtraGrid.Views.Base
Imports DevExpress.XtraGrid.Views.Grid
Imports DevExpress.XtraGrid.Columns
Private Sub GridView1_ValidatingEditor(sender As Object, e As DevExpress.XtraEditors.Controls.BaseContainerValidateEditorEventArgs) Handles GridView1.ValidatingEditor
Dim view As ColumnView = sender
Dim column As GridColumn = If(TryCast(e, EditFormValidateEditorEventArgs)?.Column, view.FocusedColumn)
If column.Name <> "colBudget" Then Exit Sub
If (Convert.ToInt32(e.Value) < 0) Or (Convert.ToInt32(e.Value) > 1000000) Then
e.Valid = False
End If
End Sub
Private Sub GridView1_InvalidValueException(sender As Object, e As DevExpress.XtraEditors.Controls.InvalidValueExceptionEventArgs) Handles GridView1.InvalidValueException
Dim view As ColumnView = sender
If view Is Nothing Then
Return
End If
e.ExceptionMode = ExceptionMode.DisplayError
e.WindowCaption = "Input Error"
e.ErrorText = "The value should be greater than 0 and less than 1,000,000"
view.HideEditor()
End Sub
|