Use DataFormValidationSummary outside RadDataForm
As of R2 2016 SP1, DataFormValidationSummary is exposed to be used outside the context of RadDataForm. The control provides the following properties:
Errors: The collection exposed by DataFormValidationSummary for adding and removing errors. It expects objects of type ErrorInfo.
HasErrors: A readonly boolean property providing information whether there are errors present in the Errors collection.
Adding DataFormValidationSummary to the Project
In order to use RadGridView in XAML, you have to add the following namespace declaration:
xmlns:telerikDataForm="clr-namespace:Telerik.Windows.Controls.Data.DataForm;assembly=Telerik.Windows.Controls.Data"
You can then define the control as demonstrated in Example 1:
Example 1: Defining the DataFormValidationSummary Control
<telerikDataForm:DataFormValidationSummary x:Name="ValidationSummary" />
Integration with RadGridView
A good example of how to use the DataFormValidationSummary outside RadDataForm would be to integrate it with the RadGridView control. One way to achieve this is to handle RadGridView's RowValidating event as shown in Example 2.
Example 2: Handling RadGridView's RowValidating Event
private void RadGridView_RowValidating(object sender, GridViewRowValidatingEventArgs e)
{
this.ValidationSummary.Errors.Clear();
var club = e.Row.DataContext as Club;
if (string.IsNullOrEmpty(club.Name) || club.Name.Length < 5)
{
this.ValidationSummary.Errors.Add(new ErrorInfo()
{
SourceFieldDisplayName = "Name",
ErrorContent = "Name is required and must be at least five characters!"
});
e.IsValid = false;
}
if (club.StadiumCapacity < 0)
{
this.ValidationSummary.Errors.Add(new ErrorInfo()
{
SourceFieldDisplayName = "StadiumCapacity",
ErrorContent = "StadiumCapacity must be positive!"
});
e.IsValid = false;
}
}
Private Sub RadGridView_RowValidating(ByVal sender As Object, ByVal e As GridViewRowValidatingEventArgs)
Me.ValidationSummary.Errors.Clear()
Dim club = TryCast(e.Row.DataContext, Club)
If String.IsNullOrEmpty(club.Name) OrElse club.Name.Length < 5 Then
Me.ValidationSummary.Errors.Add(New ErrorInfo() With {
.SourceFieldDisplayName = "Name",
.ErrorContent = "Name is required and must be at least five characters!"
})
e.IsValid = False
End If
If club.StadiumCapacity < 0 Then
Me.ValidationSummary.Errors.Add(New ErrorInfo() With {
.SourceFieldDisplayName = "StadiumCapacity",
.ErrorContent = "StadiumCapacity must be positive!"
})
e.IsValid = False
End If
End Sub