MultiRow Windows Forms > Developer's Guide > Using MultiRow > User Input Validation > Built-in Cell Validators > RequiredTypeValidator |
You can use RequiredTypeValidator and validate if the value entered in a cell matches the specified type. RequiredTypeValidator supports only DateTime, TimeSpan, and Decimal type (Numeric).
Complete the following steps to validate the value type. The example shows TextBoxCell for which a validation error occurs if text entered cannot be converted to a numeric value.
The following code displays a validation error when the value is not an Integer type.
Imports GrapeCity.Win.MultiRow Dim textBoxCell1 As New TextBoxCell() textBoxCell1.Value = "Hello" Dim requiredTypeValidator1 As New RequiredTypeValidator() requiredTypeValidator1.RequiredType = GetType(Decimal) requiredTypeValidator1.Actions.Add(New LineNotify()) textBoxCell1.Validators.Add(requiredTypeValidator1) Dim cells As Cell() = {textBoxCell1} GcMultiRow1.Template = Template.CreateGridTemplate(cells) GcMultiRow1.RowCount = 10 |
using GrapeCity.Win.MultiRow; TextBoxCell textBoxCell1 = new TextBoxCell(); textBoxCell1.Value = "Hello"; RequiredTypeValidator requiredTypeValidator1 = new RequiredTypeValidator(); requiredTypeValidator1.RequiredType = typeof(decimal); requiredTypeValidator1.Actions.Add(new LineNotify()); textBoxCell1.Validators.Add(requiredTypeValidator1); Cell[] cells = { textBoxCell1 }; 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 RequiredTypeValidator.ParsingEnabled property to True. If the RequiredTypeValidator.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(Int32) Dim requiredTypeValidator1 As New RequiredTypeValidator() requiredTypeValidator1.Actions.Add(New LineNotify()) requiredTypeValidator1.RequiredType = GetType(Decimal) requiredTypeValidator1.ParsingEnabled = True requiredTypeValidator1.FormatProvider = CultureInfo.CurrentCulture textBoxCell1.Validators.Add(requiredTypeValidator1) Dim cells As Cell() = {textBoxCell1} GcMultiRow1.Template = Template.CreateGridTemplate(cells) GcMultiRow1.RowCount = 10 |
using System.Globalization; using System.Globalization; using GrapeCity.Win.MultiRow; TextBoxCell textBoxCell1 = new TextBoxCell(); textBoxCell1.Style.Format = "#,#00"; textBoxCell1.ValueType = typeof(Int32); RequiredTypeValidator requiredTypeValidator1 = new RequiredTypeValidator(); requiredTypeValidator1.Actions.Add(new LineNotify()); requiredTypeValidator1.NullIsValid = true; requiredTypeValidator1.RequiredType = typeof(Decimal); requiredTypeValidator1.ParsingEnabled = true; requiredTypeValidator1.FormatProvider = CultureInfo.CurrentCulture; textBoxCell1.Validators.Add(requiredTypeValidator1); Cell[] cells = { textBoxCell1 }; gcMultiRow1.Template = Template.CreateGridTemplate(cells); gcMultiRow1.RowCount = 10; |