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

Support for "ValidatesOnExceptions" in RadGridView

8 Answers 210 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Marc
Top achievements
Rank 1
Marc asked on 24 Aug 2011, 05:58 PM
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);

8 Answers, 1 is accepted

Sort by
0
Nedyalko Nikolov
Telerik team
answered on 30 Aug 2011, 09:12 AM
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 >>

0
Marc
Top achievements
Rank 1
answered on 31 Aug 2011, 07:55 AM
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
0
Nedyalko Nikolov
Telerik team
answered on 02 Sep 2011, 03:41 PM
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 >>

0
Marc
Top achievements
Rank 1
answered on 02 Sep 2011, 04:49 PM
Alright, thank you!
0
Todd
Top achievements
Rank 1
answered on 13 Sep 2011, 08:04 PM
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
0
Maya
Telerik team
answered on 15 Sep 2011, 02:50 PM
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 >>

0
Todd
Top achievements
Rank 1
answered on 16 Sep 2011, 04:01 PM
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.
0
Maya
Telerik team
answered on 20 Sep 2011, 10:17 AM
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 >>

Tags
GridView
Asked by
Marc
Top achievements
Rank 1
Answers by
Nedyalko Nikolov
Telerik team
Marc
Top achievements
Rank 1
Todd
Top achievements
Rank 1
Maya
Telerik team
Share this question
or