GrapeCity MultiRow Windows Forms Documentation
User Defined Validation Actions

You can create a user-defined validation action by inheriting the CellValidateAction class.

Using Code

The following code implements a validation action to change the font color to red if there is a validation error.

[VB]

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

[CS]

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.

[VB]

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

[CS]

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;

Designer and User Defined Validation Actions

You can use the CellValidateAction Collection Editor of the designer to add a user-defined validation action.

Setting a User-defined Validation Action

Use the following steps to add the above CustomAction.

  1. Create a user-defined validation action that inherits the CellValidateAction class, and add it to the project.
  2. Build the project.
  3. Select a cell value to validate (for example, numericUpDownCell1).
  4. From the Properties window, select the Validators property and click the ... button.
  5. From the displayed CellValidator collection editor, select RangeValidator from the left-top combo box and click the Add button.
  6. From the Members list, confirm that RangeValidator has been selected.
  7. Select the MaxValue property from the property grid and type 10.
  8. Select the MinValue property from the property grid and type 0.
  9. Select the Actions property from the property grid and click the ... button.
  10. Add CustomAction in the displayed CellValidateAction collection editor.
  11. Set the ForeColor property in the property grid to Red.
  12. Click the OK button to close the CellValidateAction collection editor.
  13. Click the OK button to close the CellValidator collection editor.
See Also

 

 


Copyright © GrapeCity, inc. All rights reserved.

Support Options