The SfDataGrid provides a convenient way to validate data and indicate the errors along with its information. By default, validation error templates are displayed in red. However, the SfDataGrid allows you to customize the Validation error template or its icon by writing style for GridCell and GridRowHeaderCell. You can change the validation error template color of the cell by editing the ControlTemplate of the GridCell and also setting the error path fill color. For example, yellow. You can change the validation error template color of the RowHeader by editing the ControlTemplate of the GridRowHeaderCell and setting the path fill color as any. For example, yellow.
The control template of the GridRowHeaderCell contains two VisualStateGroups; BorderStates that specifies the BorderThickness of the GridRowHeaderCell and IndicationStates that contains the visual states, CurrentRowError, Error, CurrentRow, Editing row and AddNewRow. The validation error template color of the GridRowHeaderCell is changed by editing the visual state Error. It contains two classes, ObjectAnimationUsingKeyFrames where the error template is drawn and ColorAnimationUsingKeyFrames where the color of the error template is mentioned. The validation error template color is changed by changing the value property of the EasingColorKeyFrame.
The control template of the GridCell contains only one VisualStateGroup that contains the visual states HasError and NoError. The HasError state specifies the width of the error template of the cell and NoError state depicts the state of the cell when it has no errors. Apart from the VisualStateGroup, the control template of the GridCell has three borders. A ContentPresenter is loaded in the first border where the contents of the cell are displayed. The Second border is the CurrentCellBorder and the third border displays the error template. You can change the validation error template color of the GridCell by changing the Fill property of the path codes in the third border.
The following screenshot displays the output for the above code in the SfDataGrid.
Note: The above code examples are for WPF. For WinRT and Silverlight platforms, refer to the following samples.
|Article ID:||Published Date:||Last Revised Date:||Platform:||Control:||.NET Framework:|
or the page will be automatically redirected to sign-in page in 10 seconds.