Binding ValidationRules not displayed in Grid

4 posts, 0 answers
  1. Davidm
    Davidm avatar
    10 posts
    Member since:
    Dec 2011

    Posted 16 Mar Link to this post

    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?

  2. Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    280 posts

    Posted 17 Mar Link to this post

    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.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Davidm
    Davidm avatar
    10 posts
    Member since:
    Dec 2011

    Posted 17 Mar in reply to Stefan Nenchev Link to this post

    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?

  5. Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    280 posts

    Posted 18 Mar Link to this post

    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.
Back to Top