We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

What are the different validation events and event members? When are they triggered and how are they used?

 

The Grid offers validation in three ways:

  1. Cell-wise Validation
  2. Character-wise validation
  3. Grid validation(Cells validation)

To validate the Grid on a cell-by-cell basis, two handlers are offered. They are CurrentCellValidating and CurrentCellValidated handlers.

 

1. Cell-wise Validation

  • CurrentCellValidated: The CurrentCellValidated event is fired only when you try to leave the current cell after editing.

Event Data:                 The event handler receives an argument of type System.EventArgs.

The following code changes the text color when the cell value is greater than 50 in the GridControl. In the GridDataBoundGrid, the output lines are written based on the above condition.

The following is the code example for the GridControl:

C#

VB

The following screenshot displays the text color when the cell value is greater than 50.

Figure 1: Cell value is greater than 50

The following is the code example for the GridDataBoundGrid.

C#

VB

The following screenshot displays the cell value greater than 50.

Figure 2: Cell value is greater than 50

  • CurrentCellValidating: The CurrentCellValidating is also fired when you try to leave the current cell after editing. It is a cancellable event when the cancel property is set to true, and then the current cell focus can be made to remain in the cell.

Event Data: The event handler receives an argument of type, System.ComponentModel.CancelEventArgs, thus enabling canceling actions.

Cancel - The act of leaving the cell can be canceled by setting Cancel to true.

The following code passes when the second column entries are found to be present or absent, or else it cancels the actions and the current cell focus remains in the same cell.

The following is the code example for the GridControl:

C#

VB

The following screenshots display that the focus is not changed in the current cell by setting CurrentCellValidating event e.Cancel=true. The MessageBox is displayed.

.

Figure 3: Value to be less than 70

The following is the code example for the GridDataBoundGrid.

C#

VB

 

 

Figure 4: Value to be less than 70

2. Character-wise Validation

There is a special event called the CurrentCellValidateString that does character-wise validation.

CurrentCellValidateString: The CurrentCellValidateString is fired with each key. This examines each key stroke in a cell.

Event Data:                 The event handler receives an argument of type, Syncfusion.Windows.Forms.Grid.GridCurrentCellValidateStringEventArgs that contains data related to this event. The following GridCurrentCellValidateStringEventArgs properties provide specific information for this event.

Text - The text that is being edited in a cell is stored in the Text property.

Cancel - A key stroke in a cell can be canceled by setting Cancel to true.

The following is the code example for the GridControl:

C#

VB

The following is the code example for the GridDataBoundGrid:

C#

VB

 

The following screenshots display the CurrentCellValidateString event fired for each key in both the GridControl and GridDataBoundGrid:

Figure 5: Character-wise Validation

3. Grid Validation

To validate the whole grid, two handlers are offered in common to the GridControl and GridDataBoundControl. They are Validating and Validated handlers. A range of cells can be validated at a time in this manner. There is a special handler, ValidateFailed for the GridDataBoundGrid.

Validated: The Validated event is fired only from another control that has the CausesValidation property set to true.

Event Data: The event handler receives an argument of the type, System.EventArgs.

The following code validates all the entries of column 4 on the click of a button. If entries are found to be less than 45, a message window either shows cannot be saved or saved.

The following is the code example for the GridControl:

C#

VB

The following is the code example for the GridDataBoundGrid:

C#

VB

The following screenshot displays the GridControl.Validated and GridDataBoundGridValidated events fired.

Figure 6: GridControl.Validated event fired when the entries in 4th column is less than 45

Validating:                 The Validating event is fired only from another control that the CausesValidation property sets to true. It is a cancellable event.

Event Data: The event handler receives an argument of the type, System.ComponentModel.CancelEventArgs, thus enabling canceling action.

Cancel - The action in the external control's handler can be canceled by setting the Cancel to true, when the condition fails.

C#

VB

The following is the code example for the GridDataBoundGrid.

C#

VB

 

Figure 7: Values to be less than 50

 

ValidateFailed: The ValidateFailed event is triggered only when the validation fails. This is a special event for the GridDataBoundGrid. With the help of this handler, the default validations can be overruled by setting Handled property to true.

Event Data:                 The event handler receives an argument of the type, Syncfusion.Windows.Forms.Grid.GridValidateFailedEventArgs that contains data related to this event. The following GridValidateFailedEventArgs properties provide specific information for this event.

Handled - The code inside this handler alone is taken into action.

C#

VB

The following screenshot displays Validation failed event when characters are entered instead of values:

Figure 8: Invalid values

Samples Links:

ValidatingEvents-C#

ValidatingEvents-VB

Article ID: Published Date: Last Revised Date: Platform: Control:
682 04/30/2011 03/10/2015 Windows Forms GridControl
Did you find this information helpful?
Add Comment
You must log in to leave a comment

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon