| Visual Basic (Declaration) | |
|---|---|
Public MustInherit Class CellValidationRule | |
| C# | |
|---|---|
public abstract class CellValidationRule | |
All examples in this topic assume that the grid is bound to a list of Composer objects, unless stated otherwise.
The following example demonstrates how to create a custom CellValidationRule and add it to a column's CellValidationRules collection to provide UI-level validation.
| XAML | Copy Code |
|---|---|
<Grid xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid" | |
Implementation of the PeriodVSCompositionCountCellValidationRule validation rule. Implementation of the Person class can be found in the Validating Data topic.
| Visual Basic | Copy Code |
|---|---|
Imports System | |
Implementation of the PeriodVSCompositionCountCellValidationRule validation rule. Implementation of the Person class can be found in the Validating Data topic.
| C# | Copy Code |
|---|---|
using System; | |
When the value of a cell fails the validation process, its HasValidationError property will return true and its ValidationError property will contain a CellValidationError, which provides information on the cell in error, the error content, the exception (if one was thrown), and the validation rule that failed. If the validation rule that failed is a binding-level ValidationRule, it will be wrapped in a PassthroughCellValidationRule. Validation errors will also be reported by a row when the value of one or more of its cells fails the validation process. Like cells, when a row contains validation errors, its HasValidationError property will return true and its ValidationError property will contain a RowValidationError, which provides information on the row in error, the error content, the exception, and the validation rule that failed.
Any validation rule created from the ValidationRule class can be reused in a grid by using a PassthroughCellValidationRule, which wraps any validation rule and exposes it as a CellValidationRule.
System.Object
Xceed.Wpf.DataGrid.ValidationRules.CellValidationRule
Xceed.Wpf.DataGrid.ValidationRules.EventCellValidationRule
Xceed.Wpf.DataGrid.ValidationRules.PassthroughCellValidationRule
Supported Operating Systems: Windows Server 2003 Service Pack 1; Windows Vista; Windows XP Service Pack 2
Reference
CellValidationRule MembersXceed.Wpf.DataGrid.ValidationRules Namespace
Copy Code