This is a migrated thread and some comments may be shown as answers.

Binding ValidationRules not displayed in Grid

3 Answers 69 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Davidm
Top achievements
Rank 1
Davidm asked on 16 Mar 2016, 12:44 PM

I'am trying to implement a data validation for the columns in my RadGridView. I would like to validate the data that is loaded into the grid, not the data that is entered by the user into the grid. To to this I've written a ValidationRule which returns a ValidationResult and implemented this rule in the binding of the column:

 

<telerik:GridViewDataColumn Header="Test" >
    <telerik:GridViewDataColumn.DataMemberBinding>
        <Binding Path="MyObject.MyProperty" Converter="{StaticResource TestConverter}" NotifyOnValidationError="True">
            <Binding.ValidationRules>
                <validators:TestValidator ValidatesOnTargetUpdated="True" />
            </Binding.ValidationRules>
        </Binding>
    </telerik:GridViewDataColumn.DataMemberBinding>
</telerik:GridViewDataColumn>

These are the settings I've set on my RadGridView:

<telerik:RadGridView telerik:StyleManager.Theme="Expression_Dark" AutoGenerateColumns="False" CanUserDeleteRows="True" CanUserInsertRows="False" ShowColumnHeaders="True" SelectionMode="Extended" EnableColumnVirtualization="False" RowIndicatorVisibility="Collapsed" RowDetailsVisibilityMode="Collapsed" EditTriggers="None" ClipboardCopyMode="None" ClipboardPasteMode="None">

The ValidationRule is called when loading data into the Grid and a negative ValidationResult is returned, but the error is not displayed in the Grid. What am I doing wrong?

3 Answers, 1 is accepted

Sort by
0
Stefan Nenchev
Telerik team
answered on 17 Mar 2016, 09:40 AM
Hi David,

Have you reviewed the different validation options for the RadGridView from the following article in our documentation page - RadGridView Validation? I suggest you go through the topic and implement one of the available features. More specifically, the property level validation seems the most appropriate approach in your case. Simply apply the validation in the setter of the property the column is bound to and the error will be displayed. 

Regards,
Stefan Nenchev
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Davidm
Top achievements
Rank 1
answered on 17 Mar 2016, 10:25 AM

Yes I have read this page, but the property level validation would only work if data is edited by the grid. I think I have to explain my situation better:

I am loading data from a database using the Entity Framework DbContext and binding the results directly to the grid. Now I want to display an error in the grid if a relation to another table is null. Those relations are also simply properties containing the Object of the related table. So I need a way to dispay an error when a null value is loaded when binding of the grid, and the ValidationRules are the only thing I found that can do this. (I've already got this to work with an older version of RadGridView) Is there no way to get this to work with the latest version?

0
Stefan Nenchev
Telerik team
answered on 18 Mar 2016, 12:47 PM
Hi David,

You can apply validation through the IDataErrorInfo interface in order to display the validation errors when the RadGridView is initially bound. I have added a sample project, please review it and consider such approach as it integrates the desired behavior.

As for the approach with the ValidationRule, can you please inform me with what version of the Telerik controls you have observed the initial validation errors appearing as I have tested with several older versions and could not replicate it? If you could provide us with a sample project that reflects the working scenario it will be highly appreciated. 

Regards,
Stefan Nenchev
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
GridView
Asked by
Davidm
Top achievements
Rank 1
Answers by
Stefan Nenchev
Telerik team
Davidm
Top achievements
Rank 1
Share this question
or