MultiRow Windows Forms > Developer's Guide > Using MultiRow > User Input Validation > Built-in Cell Validators > 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.
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.
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.
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 |
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; |
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.
The following code validates a numerical value with commas, entered in the cell.
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 |
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; |