Support for "ValidatesOnExceptions" in RadGridView

9 posts, 0 answers
  1. Marc
    Marc avatar
    88 posts
    Member since:
    Jul 2011

    Posted 24 Aug 2011 Link to this post

    Hi Telerik,

    the documentations says there is support for IDataErrorInfo and INotifyDataErrorInfo in RadGridView, I know. But when my model throws, e.g. an ArgumentNullException, RadGridView displays it as well. So I thought this should work as well, if my IValueConverter on the GridViewDataColumn throws exceptions. Unfortunately it doesn't. Would be great if you could clarify this. I'm sure I'm missing something cause I'm new to Silverlight and .NET.

    This is what I do:

                          Binding binding = new Binding();
                    binding.Path = new PropertyPath("[" + id + "]");
                    binding.ValidatesOnExceptions = true;
                    binding.Mode = BindingMode.TwoWay;
                    // binding.NotifyOnValidationError = true;
                    binding.Converter = new MyConverter();
     
                    GridViewDataColumn dataColumn = new GridViewDataColumn();
                    dataColumn.UniqueName = id;
                    dataColumn.DataType = types[c];
                    dataColumn.DataMemberBinding = binding;
                    dataColumn.Header = "Header " + id;
     
                    _grid.Columns.Add(dataColumn);
  2. Nedyalko Nikolov
    Admin
    Nedyalko Nikolov avatar
    871 posts

    Posted 30 Aug 2011 Link to this post

    Hello Stephan,

    I think that this is an expected behavior, because of this line:

    binding.ValidatesOnExceptions = true;

    This will force RadGridView to show validation message when an exception is thrown by the underlying property setter.

    Let me know if this doesn't help.

    Kind regards,
    Nedyalko Nikolov
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  3. DevCraft banner
  4. Marc
    Marc avatar
    88 posts
    Member since:
    Jul 2011

    Posted 31 Aug 2011 Link to this post

    Yes, that's right and exactly what I need. But my question was more about the converter. When I throw an exception in a converter which is located between my model and the grid, the exception is NOT displayed on the grid (cell).

    Regards,
    Stephan
  5. Nedyalko Nikolov
    Admin
    Nedyalko Nikolov avatar
    871 posts

    Posted 02 Sep 2011 Link to this post

    Hi Stephan,

    Generally you should not throw exceptions inside converter and there is no built-in mechanism that will support such validation scenario. I could suggest you to use CellValidating event where you could check the "new data" (call code similar to the converter one) and set e.IsValid = false without throwing an exception.
    This will paint the "wrong" cell in red. Code should look like the following one:

    void radGridView_CellValidating(object sender, Telerik.Windows.Controls.GridViewCellValidatingEventArgs e)
            {
                if (!check(e.NewValue))
                {
                    e.IsValid = false;
                }
            }

    Let me know if you need further assistance.

    Regards,
    Nedyalko Nikolov
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  6. Marc
    Marc avatar
    88 posts
    Member since:
    Jul 2011

    Posted 02 Sep 2011 Link to this post

    Alright, thank you!
  7. Todd
    Todd avatar
    6 posts
    Member since:
    May 2011

    Posted 13 Sep 2011 Link to this post

    Hi Nedyalko,

    I can get it to paint the "wrong" cell in red using the method you described.

    But how can I get it to force open the tooltip with the message instead of requiring user to mouse over the tiny arrow at top right?

    Thanks

    Todd
  8. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 15 Sep 2011 Link to this post

    Hi Todd,

    If you require the ErrorMessage to be always visible on failed validation, you need to predefine the template of the GridViewEditorPresenter. I am sending you a sample project illustrating this approach. In this case the style is applied implicitly, so you need only to copy it in the Resources section of your UserControl.

    Kind regards,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  9. Todd
    Todd avatar
    6 posts
    Member since:
    May 2011

    Posted 16 Sep 2011 Link to this post

    Thank you!

    Your solution does now force the message to be visible.

    However, the message overlays the column to the right such that the column data is seen together with the message, or, the message is clipped to the grid width in some cases.  My desired behavior is for the message to be displayed "on top" of all elements below without clipping, just as the tool-tip behaves.
  10. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 20 Sep 2011 Link to this post

    Hi Todd,

    You may change the behavior of this error dialog and to display it above the cell - all you need to do is to change the Margin of the Border:

    <Border x:Name="border" CornerRadius="2" Background="#FFDC000C" Margin="1,1,-202,2"
                            HorizontalAlignment="Right" Visibility="Collapsed" Width="200">
                        <TextBlock Foreground="White" MaxWidth="180" Margin="8,4,8,4" TextWrapping="Wrap"
                                   Text="{TemplateBinding ErrorMessage}" HorizontalAlignment="Left"/>
                    </Border>
     
    However, if you place it above, you will probably not be able to edit the cell value afterwards. Still, you may define it so that it meets you particular requirements. 
    Considering the clipping, it cannot be removed when working with the above approach. What you may try is to still use a ToolTip, but a kind of specific one, whose Duration can be changed. Please look at this forum thread for a reference on how to set the duration of the visibility of the ToolTip.

    Regards,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top
DevCraft banner