Skip to main content

VGridControlBase.InvalidValueException Event

Enables a proper response to entering an invalid cell value to be provided.

Namespace: DevExpress.XtraVerticalGrid

Assembly: DevExpress.XtraVerticalGrid.v23.2.dll

NuGet Packages: DevExpress.Win.Navigation, DevExpress.Win.VerticalGrid

Declaration

public event InvalidValueExceptionEventHandler InvalidValueException

Event Data

The InvalidValueException event's data class is InvalidValueExceptionEventArgs. The following properties provide information specific to this event:

Property Description
ErrorText Gets or sets the error description to be displayed in the message box/tooltip. Inherited from ExceptionEventArgs.
Exception Gets the exception that caused the event. Inherited from ExceptionEventArgs.
ExceptionMode Gets or sets the type of response to supplying invalid values. Inherited from ExceptionEventArgs.
Value Gets an invalid value that caused the exception.
WindowCaption Gets or sets the caption of the error message box. Inherited from ExceptionEventArgs.

Remarks

The InvalidValueException event allows you to handle exceptions raised as a result of assigning invalid values to cells. Generally, this takes place when using a wrong value type or when an exception is raised during validation (the VGridControlBase.ValidatingEditor event).

The InvalidValueException event fires regardless of whether the value was entered by an end-user or changed in code. Handle this event to perform an appropriate exception handling, as shown in the example below. The event parameter provides a number of properties that allow you to get the exception information, specify whether the exception should be raised, etc.

For more information, see Validation.

Example

The following example prohibits assignment of invalid values to “Department Budget” child rows. The cell’s value should be no greater than 100,000. The VGridControlBase.ValidatingEditor event is handled to check the entered value’s validity. The VGridControlBase.InvalidValueException event is handled to display an exception message box if an invalid value is assigned. In this instance, the VGridControlBase.HideEditor method is called to discard the changes made and destroy the cell’s editor.

using DevExpress.XtraVerticalGrid;
using DevExpress.XtraEditors.Controls;

private void vGridControl1_ValidatingEditor(object sender, 
BaseContainerValidateEditorEventArgs e) {
  VGridControl vGrid = sender as VGridControl;
  if (vGrid.FocusedRow.Name == "rowAnatomy" || 
      vGrid.FocusedRow.Name == "rowBusiness" ||
      vGrid.FocusedRow.Name == "rowDesign" || 
      vGrid.FocusedRow.Name == "History")
     if (Convert.ToInt32(e.Value) > 100000) e.Valid = false;
}

private void vGridControl1_InvalidValueException(object sender, 
InvalidValueExceptionEventArgs e) {
   VGridControl vGrid = sender as VGridControl;
   e.ExceptionMode = ExceptionMode.DisplayError;
   e.WindowCaption = "Input Error";
   e.ErrorText = "The value should be less than 100000";

   // Destroying the editor and discarding the wrong changes made within the edited cell
   vGrid.HideEditor();
}
See Also