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

Cell Validation

4 Answers 164 Views
GridView
This is a migrated thread and some comments may be shown as answers.
nbahl
Top achievements
Rank 1
nbahl asked on 17 Mar 2010, 10:54 PM
Hello,
Is there a way to automatically display the ErrorMessage when validating data on a cell level?  So the user does not have to hover over the corner of the cell to see the error message.

Thank You,
Nate

4 Answers, 1 is accepted

Sort by
0
Nedyalko Nikolov
Telerik team
answered on 22 Mar 2010, 03:44 PM
Hi nbahl,

Unfortunately this error message is displayed with tooltip which is not so easy to control when to show and when to hide. However you can customize GridViewEditorPresenter style in order to achieve this. Below you can find the original style for GridViewEditorPresenter and a modified one which I think covers your scenario.

Original style:
 
<Style TargetType="{x:Type telerik:GridViewEditorPresenter}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type telerik:GridViewEditorPresenter}">
                            <Grid>
                                <ContentPresenter Margin="1,1,1,2" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                                <Border x:Name="ValidationErrorElement" Margin="1,1,1,2" Visibility="Collapsed" BorderBrush="#FFDC000C" BorderThickness="1" CornerRadius="1">
                                    <Border.ToolTip>
                                        <ToolTip x:Name="validationTooltip" Content="{TemplateBinding ErrorMessage}" Placement="Right"
                                                 Opened="validationTooltip_Opened">
                                            <ToolTip.Template>
                                                <ControlTemplate TargetType="{x:Type ToolTip}">
                                                    <Grid x:Name="Root" Margin="4,0,0,0" Opacity="1">
                                                        <Border BorderBrush="#FFDC000C" BorderThickness="1" CornerRadius="1">
                                                            <Border BorderBrush="White" BorderThickness="1">
                                                                <Border.Background>
                                                                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                                                        <GradientStop Color="#FFFF424C" Offset="1" />
                                                                        <GradientStop Color="#FFC92931" />
                                                                    </LinearGradientBrush>
                                                                </Border.Background>
                                                                <TextBlock Margin="4" MaxWidth="250" VerticalAlignment="Center" Foreground="White" Text="{TemplateBinding Content}" TextWrapping="Wrap" />
                                                            </Border>
                                                        </Border>
                                                    </Grid>
                                                </ControlTemplate>
                                            </ToolTip.Template>
                                        </ToolTip>
                                    </Border.ToolTip>
                                    <Grid HorizontalAlignment="Right" Margin="1,-4,-4,0" VerticalAlignment="Top" Width="12" Height="12" Background="Transparent">
                                        <Path Fill="#FFDC000C" Margin="1,3,0,0" Data="M1,0L6,0A2,2,90,0,1,8,2L8,7z" />
                                        <Path Fill="White" Margin="1,3,0,0" Data="M0,0L2,0 8,6 8,8" />
                                    </Grid>
                                </Border>
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsContentValid" Value="False">
                                    <Setter Property="Visibility" TargetName="ValidationErrorElement" Value="Visible" />
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
                <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>
 
New style:     
             
<Style TargetType="{x:Type telerik:GridViewEditorPresenter}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type telerik:GridViewEditorPresenter}">
                <Grid>
                    <ContentPresenter Margin="1,1,1,2" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                    <Border x:Name="ValidationErrorElement" Margin="1,1,1,2" Visibility="Collapsed" BorderBrush="#FFDC000C" BorderThickness="1" CornerRadius="1" />
                </Grid>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsContentValid" Value="False">
                        <Setter Property="Visibility" TargetName="ValidationErrorElement" Value="Visible" />
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
    <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>

You should set this style as a general style.
Let me know if this doesn't help.


Greetings,
Nedyalko Nikolov
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
nbahl
Top achievements
Rank 1
answered on 22 Mar 2010, 06:00 PM
Nedyalko,
Thank you for the help but with this style I am not getting any message to appear.  In the CellValidating method I am doing a check on the value and if NOT valid I'm setting the ErrorMessage and IsValid=false, is this the correct way to handle it?

Thanks,
Nate
0
Nedyalko Nikolov
Telerik team
answered on 23 Mar 2010, 06:34 PM
Hi nbahl,

I'm attaching a working sample project that demonstrates this approach. Excuse me for the copy/paste mistake.
Let me know how this works on your end.

Sincerely yours,
Nedyalko Nikolov
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
nbahl
Top achievements
Rank 1
answered on 23 Mar 2010, 07:10 PM
Works perfect, thank you
Tags
GridView
Asked by
nbahl
Top achievements
Rank 1
Answers by
Nedyalko Nikolov
Telerik team
nbahl
Top achievements
Rank 1
Share this question
or