MultiRow Windows Forms > Developer's Guide > Using MultiRow > User Input Validation > User Defined Validation Actions |
You can create a user-defined validation action by inheriting the CellValidateAction class.
The following code implements a validation action to change the font color to red if there is a validation error.
Imports GrapeCity.Win.MultiRow Public Class CustomAction Inherits CellValidateAction Protected Overrides Sub DoAction(context As ValidateActionContext) If Not context.IsValid Then context.GcMultiRow.CurrentCell.Style.ForeColor = Me.ForeColor Else context.GcMultiRow.CurrentCell.Style.ForeColor = Color.Empty End If End Sub Public ForeColor As Color Public Overrides Function Clone() As CellValidateAction Dim action As CustomAction = TryCast(MyBase.Clone(), CustomAction) action.ForeColor = Me.ForeColor Return action End Function End Class |
using GrapeCity.Win.MultiRow; public class CustomAction : CellValidateAction { protected override void DoAction(ValidateActionContext context) { if (!context.IsValid) { context.GcMultiRow.CurrentCell.Style.ForeColor = this.ForeColor; } else { context.GcMultiRow.CurrentCell.Style.ForeColor = Color.Empty; } } public Color ForeColor { get; set; } public override CellValidateAction Clone() { CustomAction action = base.Clone() as CustomAction; action.ForeColor = this.ForeColor; return action; } } |
The following code shows an example of a user-defined custom action.
Imports GrapeCity.Win.MultiRow Dim rangeValidator1 As New RangeValidator() rangeValidator1.MaxValue = 10 rangeValidator1.MinValue = 0 Dim customAction1 As New CustomAction() customAction1.ForeColor = Color.Red rangeValidator1.Actions.Add(customAction1) Dim numericUpDownCell1 As New NumericUpDownCell() numericUpDownCell1.Name = "numericUpDownCell1" numericUpDownCell1.Validators.Add(rangeValidator1) Dim cells As Cell() = {numericUpDownCell1} GcMultiRow1.Template = Template.CreateGridTemplate(cells) GcMultiRow1.RowCount = 10 |
using GrapeCity.Win.MultiRow; RangeValidator rangeValidator1 = new RangeValidator(); rangeValidator1.MaxValue = 10; rangeValidator1.MinValue = 0; CustomAction customAction1 = new CustomAction(); customAction1.ForeColor = Color.Red; rangeValidator1.Actions.Add(customAction1); NumericUpDownCell numericUpDownCell1 = new NumericUpDownCell(); numericUpDownCell1.Name = "numericUpDownCell1"; numericUpDownCell1.Validators.Add(rangeValidator1); Cell[] cells = { numericUpDownCell1 }; gcMultiRow1.Template = Template.CreateGridTemplate(cells); gcMultiRow1.RowCount = 10; |
You can use the CellValidateAction Collection Editor of the designer to add a user-defined validation action.
Use the following steps to add the above CustomAction.