You can create validators to validate the user data.
You can display a list of valid values for the user and display an invalid data image if the user types invalid data.
The default invalid image is a red ellipse.
You can use any of several types of validator methods to create the validation criteria.
Set the HighlightInvalidData property to use the red ellipse as an invalid data image. You can also customize the invalid data image with the InvalidDataPresenter control.
The following code uses different types of validators to validate the data in B1, B2, and B3.
CS |
Copy Code |
---|---|
gcSpreadSheet1.HighlightInvalidData = true; var valid1 = GrapeCity.Xaml.SpreadSheet.Data.DataValidator.CreateNumberValidator(GrapeCity.Xaml.SpreadSheet.Data.ComparisonOperator.GreaterThan, "5", "20", true); var valid2 = GrapeCity.Xaml.SpreadSheet.Data.DataValidator.CreateTextLengthValidator(GrapeCity.Xaml.SpreadSheet.Data.ComparisonOperator.GreaterThan, "4", "20"); |
VB |
Copy Code |
---|---|
GcSpreadSheet1.HighlightInvalidData = True Dim valid1 = GrapeCity.Xaml.SpreadSheet.Data.DataValidator.CreateNumberValidator(GrapeCity.Xaml.SpreadSheet.Data.ComparisonOperator.GreaterThan, "5", "20", True) Dim valid2 = GrapeCity.Xaml.SpreadSheet.Data.DataValidator.CreateTextLengthValidator(GrapeCity.Xaml.SpreadSheet.Data.ComparisonOperator.GreaterThan, "4", "20") |
The following code customizes the invalid data image.
<Page.Resources>
<Style TargetType="UI:InvalidDataPresenter">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="UI:InvalidDataPresenter">
<Grid Background="{TemplateBinding Background}">
<Ellipse Stroke="Orange"
StrokeThickness="2"
Margin="-6,-3,-6,-3"
/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Page.Resources>
CS |
Copy Code |
---|---|
gcSpreadSheet1.Sheets[0].Cells[0, 2].Value = 5; gcSpreadSheet1.Sheets[0].Cells[1, 2].Value = 4; gcSpreadSheet1.Sheets[0].Cells[2, 2].Value = 5; gcSpreadSheet1.HighlightInvalidData = true; var valid = GrapeCity.Xaml.SpreadSheet.Data.DataValidator.CreateFormulaListValidator("$C$1:$C$3"); gcSpreadSheet1.Sheets[0].Cells[0, 1].DataValidator = valid; gcSpreadSheet1.Sheets[0].Cells[0, 0].Text = "Formulas"; |
VB |
Copy Code |
---|---|
GcSpreadSheet1.Sheets(0).Cells(0, 2).Value = 5 GcSpreadSheet1.Sheets(0).Cells(1, 2).Value = 4 GcSpreadSheet1.Sheets(0).Cells(2, 2).Value = 5 GcSpreadSheet1.HighlightInvalidData = True Dim valid = GrapeCity.Xaml.SpreadSheet.Data.DataValidator.CreateFormulaListValidator("$C$1:$C$3") GcSpreadSheet1.Sheets(0).Cells(0, 1).DataValidator = valid GcSpreadSheet1.Sheets(0).Cells(0, 0).Text = "Formulas" |