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
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 >>
Regards,
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 >>
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
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.
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
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.
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 >>