MultiRow Windows Forms > Developer's Guide > Using MultiRow > User Input Validation > Customizing the Validation Information |
The GcMultiRow.CellValidateInfoNeeded event occurs when the validation of a cell is performed. You can use this event to customize the information that is displayed as the validation result.
You can use the IsValid property to retrieve whether the validation was successful in the GcMultiRow.CellValidateInfoNeeded event. In addition, you can use the ValidateContext.ValidateInfo property to set the validation information.
The following code demonstrates when the validation is successful, and when there is an error when using the RangeValidator and Notification using Three-State Icon.
Imports GrapeCity.Win.MultiRow Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Dim numericUpDownCell1 As New NumericUpDownCell() Dim rangeValidator1 As New RangeValidator() rangeValidator1.RequiredType = GetType(Integer) rangeValidator1.MaxValue = 10 rangeValidator1.MinValue = 1 rangeValidator1.NullIsValid = False rangeValidator1.Actions.Add(New ThreeStateIconNotify()) numericUpDownCell1.Validators.Add(rangeValidator1) Dim cells As Cell() = {numericUpDownCell1} GcMultiRow1.Template = Template.CreateGridTemplate(cells) GcMultiRow1.RowCount = 10 End Sub Private Sub GcMultiRow1_CellValidateInfoNeeded(sender As Object, e As CellValidateInfoNeededEventArgs) Handles GcMultiRow1.CellValidateInfoNeeded If TypeOf e.CellValidator Is RangeValidator Then If e.IsValid Then e.ValidateContext.ValidateInfo = "This value is correct." Else If e.ValidateContext.EditedFormattedValue > 10 Then e.ValidateContext.ValidateInfo = "Please enter a value which is less than or equal to 10." End If If e.ValidateContext.EditedFormattedValue < 1 Then e.ValidateContext.ValidateInfo = "Please enter a value which is greater than 1." End If End If End If End Sub |
using GrapeCity.Win.MultiRow; private void Form1_Load(object sender, EventArgs e) { NumericUpDownCell numericUpDownCell1 = new NumericUpDownCell(); RangeValidator rangeValidator1 = new RangeValidator(); rangeValidator1.RequiredType = typeof(int); rangeValidator1.MaxValue = 10; rangeValidator1.MinValue = 1; rangeValidator1.NullIsValid = false; rangeValidator1.Actions.Add(new ThreeStateIconNotify()); numericUpDownCell1.Validators.Add(rangeValidator1); Cell[] cells = { numericUpDownCell1 }; gcMultiRow1.Template = Template.CreateGridTemplate(cells); gcMultiRow1.RowCount = 10; } private void gcMultiRow1_CellValidateInfoNeeded(object sender, CellValidateInfoNeededEventArgs e) { if (e.CellValidator is RangeValidator) { if (e.IsValid) { e.ValidateContext.ValidateInfo = "This value is correct." ; } else { if (Convert.ToInt32(e.ValidateContext.EditedFormattedValue) > 10) { e.ValidateContext.ValidateInfo = "Please enter a value which is less than or equal to 10." ; } if(Convert.ToInt32(e.ValidateContext.EditedFormattedValue) < 1) { e.ValidateContext.ValidateInfo = "Please enter a value which is greater than 1." ; } } } } |