Hi,
I'm trying to get a behavior equals the behavior when BindingValidationError is fired ...
I'm trying to get a behavior equals the behavior when BindingValidationError is fired ...
I'm implementing the CellValidating event and when it is necessary (my business logic) I set the IsValid property to false and put my message into ErrorMessage property.
All works fine as is expected the cell appears with a red border and a error tooltip is created.But ... when I try put some string in a double field, the BindingValidationError is fired after CellValidating and before CellValidated, correctly ? So, the error tooltip appears without necessity to point the mouse hover the cell.
What I need is the same behavior in both situations. When my custom validation is executed or when an BindingException is thrown, in both cases I would like to show an error message without necessity to point the mouse there.
I tried to throw an exception in my cell validating implementation but I can't get the approach that I expected.
I'll attach an image ...
4 Answers, 1 is accepted
0
Hi Otávio,
You may alter this behavior by editing the template of GridViewCell and predefining the UI validation logic in this template. The key part is to replace the validation tooltip template with a standard PopUp control, whose content appears when a cell enters in its Invalid State.
I have prepared an example for you that demonstrates this approach, feel free to customize it in the way you need.
Please let me know how this works for you.
Regards,
Vanya Pavlova
the Telerik team
You may alter this behavior by editing the template of GridViewCell and predefining the UI validation logic in this template. The key part is to replace the validation tooltip template with a standard PopUp control, whose content appears when a cell enters in its Invalid State.
I have prepared an example for you that demonstrates this approach, feel free to customize it in the way you need.
Please let me know how this works for you.
Regards,
Vanya Pavlova
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Otávio
Top achievements
Rank 1
answered on 05 Apr 2011, 04:33 PM
My problem is that my business objects is deserialized from WCF and they don't have INotifyDataErrorInfo or IEditableObjectMembers implementation.
I tried use your solution making the validation into CellValidating event ... the tooltip (PopUp) appears as expected (it is not necessary to point the mouse) but the text that I put into ErroMessage isn't appearing ....
It works only if I use these interfaces that I mentioned before.
I'm making the validation in this method:
I'm sending a image with examples ...
A cell that is using the template you send-me, pop-up appears without a text.
A cell that is not using the template, the tooltip only appears if I put the mouse over there.
Thanks
ps. I tried set the tooltip isopen to true in the same template that you edited ... but it crashed my app ....
I tried use your solution making the validation into CellValidating event ... the tooltip (PopUp) appears as expected (it is not necessary to point the mouse) but the text that I put into ErroMessage isn't appearing ....
It works only if I use these interfaces that I mentioned before.
I'm making the validation in this method:
this
.radGridView.CellValidating += radGridView_CellValidating;
private
void
radGridView_CellValidating(
object
sender, GridViewCellValidatingEventArgs e)
{e.IsValid =
false
;
e.ErrorMessage =
"REQUIRED";
}
I'm sending a image with examples ...
A cell that is using the template you send-me, pop-up appears without a text.
A cell that is not using the template, the tooltip only appears if I put the mouse over there.
Thanks
ps. I tried set the tooltip isopen to true in the same template that you edited ... but it crashed my app ....
0
Hello Otávio,
You may see the result at the attached picture. In a similiar way you may modify the appearance of this popup to directly match the default appearance of the GridViewCell's ValidationToolTip.
Please try the markup above and let me know how it works for you.
Vanya Pavlova
the Telerik team
I have spent some time to research this case and it seems that the ErrorMesssage property that we need to use is not directly accessible from this template. If you predefine the template of the GridViewEditorPresenter you will be able to see the predefined ErorMessage within RadGridView's CellValidating event, please use the sample below:
<
SolidColorBrush
x:Key
=
"ControlOuterBorder_Invalid"
Color
=
"#FFDB000C"
/>
<
SolidColorBrush
x:Key
=
"ControlInnerBorder_Invalid"
Color
=
"White"
/>
<
ControlTemplate
x:Key
=
"GridViewEditorPresenterTemplate"
TargetType
=
"telerik:GridViewEditorPresenter"
>
<
Grid
>
<
VisualStateManager.VisualStateGroups
>
<
VisualStateGroup
x:Name
=
"ValueStates"
>
<
VisualState
x:Name
=
"Valid"
/>
<
VisualState
x:Name
=
"InvalidFocusedState"
>
<
Storyboard
>
<
ObjectAnimationUsingKeyFrames
Storyboard.TargetProperty
=
"Visibility"
Storyboard.TargetName
=
"ValidationErrorElement"
>
<
DiscreteObjectKeyFrame
KeyTime
=
"0:0:0"
Value
=
"Visible"
/>
</
ObjectAnimationUsingKeyFrames
>
<
ObjectAnimationUsingKeyFrames
Storyboard.TargetProperty
=
"Visibility"
Storyboard.TargetName
=
"Terror"
>
<
DiscreteObjectKeyFrame
KeyTime
=
"0:0:0"
Value
=
"Visible"
/>
</
ObjectAnimationUsingKeyFrames
>
</
Storyboard
>
</
VisualState
>
</
VisualStateGroup
>
</
VisualStateManager.VisualStateGroups
>
<
ContentPresenter
Margin
=
"1,1,1,2"
VerticalAlignment
=
"{TemplateBinding VerticalContentAlignment}"
/>
<
Border
x:Name
=
"ValidationErrorElement"
BorderBrush
=
"{StaticResource ControlOuterBorder_Invalid}"
BorderThickness
=
"1"
CornerRadius
=
"1"
Margin
=
"1,1,1,2"
Visibility
=
"Collapsed"
>
<
Grid
Background
=
"Transparent"
HorizontalAlignment
=
"Right"
Height
=
"12"
Margin
=
"1,-4,-4,0"
VerticalAlignment
=
"Top"
Width
=
"12"
>
<
Path
Data
=
"M 1,0 L6,0 A 2,2 90 0 1 8,2 L8,7 z"
Fill
=
"{StaticResource ControlOuterBorder_Invalid}"
Margin
=
"1,3,0,0"
/>
<
Path
Data
=
"M 0,0 L2,0 L 8,6 L8,8"
Fill
=
"{StaticResource ControlInnerBorder_Invalid}"
Margin
=
"1,3,0,0"
/>
</
Grid
>
</
Border
>
<
Popup
IsOpen
=
"True"
>
<
Border
x:Name
=
"Terror"
Visibility
=
"Collapsed"
CornerRadius
=
"2"
Background
=
"#FFEFEFEF"
Margin
=
"30"
BorderBrush
=
"#FF979797"
BorderThickness
=
"1"
Height
=
"26"
>
<
ContentControl
Content
=
"{TemplateBinding ErrorMessage}"
ContentTemplate
=
"{TemplateBinding ContentTemplate}"
Foreground
=
"Red"
VerticalAlignment
=
"Center"
HorizontalAlignment
=
"Right"
FontSize
=
"10"
/>
</
Border
>
</
Popup
>
</
Grid
>
</
ControlTemplate
>
<
Style
TargetType
=
"telerik:GridViewEditorPresenter"
>
<
Setter
Property
=
"Template"
Value
=
"{StaticResource GridViewEditorPresenterTemplate}"
/>
<
Setter
Property
=
"VerticalAlignment"
Value
=
"Stretch"
/>
<
Setter
Property
=
"HorizontalAlignment"
Value
=
"Stretch"
/>
<
Setter
Property
=
"VerticalContentAlignment"
Value
=
"Center"
/>
<
Setter
Property
=
"HorizontalContentAlignment"
Value
=
"Stretch"
/>
<
Setter
Property
=
"Padding"
Value
=
"1,1,1,2"
/>
</
Style
>
</
UserControl.Resources
>
<
Grid
x:Name
=
"LayoutRoot"
Background
=
"White"
>
<
telerik:RadGridView
x:Name
=
"radGridView"
CellValidating
=
"radGridView_CellValidating"
AutoGenerateColumns
=
"False"
>
<
telerik:RadGridView.Columns
>
<
telerik:GridViewDataColumn
Header
=
"First Name"
DataMemberBinding
=
"{Binding FirstName}"
/>
<
telerik:GridViewDataColumn
Header
=
"Last Name"
Width
=
"90"
DataMemberBinding
=
"{Binding LastName}"
>
</
telerik:GridViewDataColumn
>
<
telerik:GridViewDataColumn
Header
=
"BirthDay"
DataMemberBinding
=
"{Binding BirthDay}"
/>
<
telerik:GridViewDataColumn
Header
=
"Age"
DataMemberBinding
=
"{Binding Age}"
/>
</
telerik:RadGridView.Columns
>
</
telerik:RadGridView
>
You may see the result at the attached picture. In a similiar way you may modify the appearance of this popup to directly match the default appearance of the GridViewCell's ValidationToolTip.
Please try the markup above and let me know how it works for you.
Vanya Pavlova
the Telerik team
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Public Issue Tracking
system and vote to affect the priority of the items
0
Otávio
Top achievements
Rank 1
answered on 05 Apr 2011, 07:36 PM
I'm having troubles to use this template.
I think I'm not able to edit this template I will appreciate if you could send me a sample solution.
Here I make the changes that you suggested me but now nothing is happing. I think that I made a mistake editing this template.
All what I've done was change my UserControlResource using the code that you showed in the last post. But it didn't works =/ ...
Thanks and sorry about the inconvenient and about my english ... I'm not a good speaker ...
I think I'm not able to edit this template I will appreciate if you could send me a sample solution.
Here I make the changes that you suggested me but now nothing is happing. I think that I made a mistake editing this template.
All what I've done was change my UserControlResource using the code that you showed in the last post. But it didn't works =/ ...
Thanks and sorry about the inconvenient and about my english ... I'm not a good speaker ...