GrapeCity MultiRow Windows Forms Documentation
RangeValidator Class
Members  Example 


Represents a special CellValidator that validates whether the specified value is between the range specified by MinValue and MaxValue.
Object Model
RangeValidator ClassValidateActionCollection ClassCellValidateAction Class
Syntax
<DefaultPropertyAttribute("RequiredType")>
<ToolboxBitmapAttribute()>
Public Class RangeValidator 
   Inherits CellValidator
   Implements INamedObject 
Dim instance As RangeValidator
[DefaultProperty("RequiredType")]
[ToolboxBitmap()]
public class RangeValidator : CellValidator, INamedObject  
Remarks

This CellValidator validates whether the value is between MinValue and MaxValue. You should specify the validated value's type with the RequiredType property.

If you do not specify the RequiredType, this CellValidator uses its owner Cell's Cell.ValueType or Cell.FormattedValueType (if ValueType is a null reference (Nothing in Visual Basic)) as the required type.

Once RequiredType is set to a new value, MinValue and MaxValue are set to a null reference (Nothing in Visual Basic).

Check that the validated value, MinValue, and MaxValue are System.IComparable values using this CellValidator.

Example
The following code example uses the RangeValidator to validate whether the committed value is between MinValue and MaxValue. If you enter edit mode and input 49 (outside the range), and then press the Enter key to end edit mode, a red underline is displayed to show the validation failed. If you input 55 (in range), and then press the Enter key, no underline is displayed, and the validation is successful. This example is part of a larger example available in CellValidator.
void setRangeValidator_Click(object sender, EventArgs e)
        {
            Template template = Template.CreateGridTemplate(1);

            //Create one RangeValidator to validate whether the committed value is in range.
            RangeValidator rangValidator = new RangeValidator();
            //Set the RequiredType first, then set other Properties.
            rangValidator.RequiredType = typeof(int);
            rangValidator.MinValue = 5;
            rangValidator.MaxValue = 10;
            rangValidator.NullIsValid = false;

            LineNotify lineNotifyAction = new LineNotify();
            //When you end edit mode, the action is done (press Enter key)
            lineNotifyAction.DoActionReason = ValidateReasons.EndEdit;
            lineNotifyAction.LineColor = Color.Red;

            rangValidator.Actions.Add(lineNotifyAction);

            template.Row.Cells[0].Validators.Add(rangValidator);

            this.gcMultiRow1.Template = template;
            label.Text = "The RangeValidator's MinValue is 5, MaxValue is 10, input 4 (not in the range) in one cell, press 
Enter key to trigger validation (DoActionReason is EndEdit), a red underline is shown.";
        }
Private Sub setRangeValidator_Click(ByVal sender As Object, ByVal e As EventArgs) Handles 
setRangeValidator.Click
        Dim template As Template = template.CreateGridTemplate(1)

        'Create one RangeValidator to validate whether the committed value is in range.
        Dim rangValidator As New RangeValidator()
        'Set the RequiredType first, then set other Properties.
        rangValidator.RequiredType = GetType(Integer)
        rangValidator.MinValue = 5
        rangValidator.MaxValue = 10
        rangValidator.NullIsValid = False

        Dim lineNotifyAction As New LineNotify()
        'When you end edit mode, the action is done (press Enter key)
        lineNotifyAction.DoActionReason = ValidateReasons.EndEdit
        lineNotifyAction.LineColor = Color.Red

        rangValidator.Actions.Add(lineNotifyAction)

        template.Row.Cells(0).Validators.Add(rangValidator)

        Me.gcMultiRow1.Template = template
        label.Text = "The RangeValidator's MinValue is 5, MaxValue is 10, input 4 (not in range) in one cell, press Enter 
key to trigger validation (DoActionReason is EndEdit), a red underline is shown."
    End Sub
Inheritance Hierarchy

System.Object
   GrapeCity.Win.MultiRow.CellValidator
      GrapeCity.Win.MultiRow.RangeValidator

Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

RangeValidator Members
GrapeCity.Win.MultiRow Namespace
CellValidator Class

 

 


Copyright © GrapeCity, inc. All rights reserved.