GrapeCity MultiRow Windows Forms Documentation
RangeValidator

You can use RangeValidator to validate if a cell's value is within the specified range or not. A validation error occurs if the value does not fall inside the specified range.

Using Designer

Complete the following steps to set RangeValidator. The example sets up a NumericUpDownCell for which a validation error occurs if the value lies outside the range of 0 to 10.

  1. Select a cell for which to validate the value (for example, numericUpDownCell1).
  2. From the Properties window, select the Validators property and click the ... button.
  3. From the displayed CellValidator collection editor, select RangeValidator from the top-left combo box and click the Add button.
  4. From the Members list, confirm that RangeValidator has been selected.
  5. Select the MaxValue property from the property grid and type 10.
  6. Select the MinValue property from the property grid and type 0.
  7. Select the Actions property from the property grid and click the ... button.
  8. Add LineNotify in the displayed CellValidateAction collection editor.
  9. Click the OK button and close the CellValidateAction collection editor.
  10. Click the OK button and close the CellValidator collection editor.
  11. Change the document window tab of the designer to Runtime.
  12. Type 12, move the focus from the cell, and confirm the occurrence of the validation error.
  13. Remove 12 and type 9, move focus from the cell, and confirm that no error occurs.

Using Code

The following code displays a validation error when a number outside the range of 0 to 10 (such as -1 or 50) has been entered.

[VB]

Imports GrapeCity.Win.MultiRow

Dim numericUpDownCell1 As New NumericUpDownCell()
Dim rangeValidator1 As New RangeValidator()
rangeValidator1.RequiredType = GetType(Integer)
rangeValidator1.MaxValue = 10
rangeValidator1.MinValue = 0
rangeValidator1.Actions.Add(New LineNotify())
numericUpDownCell1.Validators.Add(rangeValidator1)

Dim cells As Cell() = {numericUpDownCell1}
GcMultiRow1.Template = Template.CreateGridTemplate(cells)
GcMultiRow1.RowCount = 10

[CS]

using GrapeCity.Win.MultiRow;

NumericUpDownCell numericUpDownCell1 = new NumericUpDownCell();
RangeValidator rangeValidator1 = new RangeValidator();
rangeValidator1.RequiredType = typeof(int);
rangeValidator1.MaxValue = 10;
rangeValidator1.MinValue = 0;
rangeValidator1.Actions.Add(new LineNotify());
numericUpDownCell1.Validators.Add(rangeValidator1);

Cell[] cells = { numericUpDownCell1 };
gcMultiRow1.Template = Template.CreateGridTemplate(cells);
gcMultiRow1.RowCount = 10;

Validation of Numerical Values Including Commas

You can convert the string representation of a number to an integer equivalent and perform validation for that converted vaue, by setting the RangeValidator.ParsingEnabled property to True. If the ParsingEnabled property is set to True, you can use the FormatProvider property to specify the culture.

Using Code

The following code validates a numerical value with commas, entered in the cell.

[VB]

Imports System.Globalization
Imports GrapeCity.Win.MultiRow

Dim textBoxCell1 As New TextBoxCell()
textBoxCell1.Style.Format = "#,#00"
textBoxCell1.ValueType = GetType(Integer)
Dim rangeValidator1 As New RangeValidator()
rangeValidator1.MaxValue = 10000
rangeValidator1.MinValue = 0
rangeValidator1.ParsingEnabled = True
rangeValidator1.FormatProvider = CultureInfo.CurrentCulture
rangeValidator1.Actions.Add(New LineNotify())
rangeValidator1.RequiredType = GetType(Decimal)
textBoxCell1.Validators.Add(rangeValidator1)

Dim cells As Cell() = {textBoxCell1}
GcMultiRow1.Template = Template.CreateGridTemplate(cells)
GcMultiRow1.RowCount = 10

[CS]

using System.Globalization;
using GrapeCity.Win.MultiRow;

TextBoxCell textBoxCell1 = new TextBoxCell();
textBoxCell1.Style.Format = "#,#00";
textBoxCell1.ValueType = typeof(int);
RangeValidator rangeValidator1 = new RangeValidator();
rangeValidator1.MaxValue = 10000;
rangeValidator1.MinValue = 0;
rangeValidator1.ParsingEnabled = true;
rangeValidator1.FormatProvider = CultureInfo.CurrentCulture;
rangeValidator1.Actions.Add(new LineNotify());
rangeValidator1.RequiredType = typeof(Decimal);
textBoxCell1.Validators.Add(rangeValidator1);

Cell[] cells = { textBoxCell1 };
gcMultiRow1.Template = Template.CreateGridTemplate(cells);
gcMultiRow1.RowCount = 10;
See Also

 

 


Copyright © GrapeCity, inc. All rights reserved.

Support Options