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

Force grid view validation

13 Answers 429 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Arthur
Top achievements
Rank 1
Arthur asked on 16 Jul 2012, 09:15 AM
Hi all,

I have two grids. Grid A has data where some of the columns have drop downs. Grid B is used to administrate the lists in the those drop downs.

When a change occurs in Grid B then the values in Grid A are updated using INotifyPropertyChanged. However, I also want validation to kick in (Its possible to delete values from Grid B but Grid A needs to have appropriate values)

For basic cell level validation I have used the cell validating event and that works pretty well. If possible, when Grid B has been updated I would want cell validation to start.

Thanks in advance

Arthur

13 Answers, 1 is accepted

Sort by
0
Nedyalko Nikolov
Telerik team
answered on 16 Jul 2012, 02:22 PM
Hi,

The only way to use CellValidating event, item should enter in edit mode, since CellValidating event is fired when cell is about to exit edit mode. I would suggest you to change the validation mechanism - validate on data layer instead of UI layer. You could use RadGridView's support for IDataErrorInfo interface.

Regards,
Nedyalko Nikolov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Arthur
Top achievements
Rank 1
answered on 16 Jul 2012, 04:43 PM
Ok thanks Nedyalko ,


Previously I was using the  GridViewEditorPresenter to style the border and the tooltip but that doesn't now work. Could you recommend a different approach to now style the invalid cells?
0
Nedyalko Nikolov
Telerik team
answered on 17 Jul 2012, 06:25 AM
Hello,

You have to style GridViewCell element itself. Inside GridViewCell style you will find almost same ValidationTooltip powered by "CellValid" and "CellInvalid" visual states. For .NET 3.5 you can use GridViewCell.IsValid inside triggers.

Kind regards,
Nedyalko Nikolov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Arthur
Top achievements
Rank 1
answered on 17 Jul 2012, 08:12 AM
Thanks,

Do you happen to have a xaml example for the template style?

0
Vanya Pavlova
Telerik team
answered on 17 Jul 2012, 08:25 AM
Hello Arthur,

 


As you may know we ship our themes as separate projects. You may find the XAML files for all Telerik themes from the Themes folder of your personal installation. If you have Microsoft Expression Blend you may extract the default templates of any RadGridView part for both WPF versions (3.5/4.0). I am attaching you the default template of GridViewCell which you may use for testing purposes. 
Thank you!   




All the best,
Vanya Pavlova
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Arthur
Top achievements
Rank 1
answered on 19 Jul 2012, 04:03 PM
Hi Vanya,


Thanks  for the sample. Unfortunately, I have not had any sucess with it. I knocked up a sample myself and used your default style for the gridviewcell to try to change the cell style in a RadGridView (attached).

Note had to name to .gif to attach. Please rename to .zip

I am using CellStyle on the column to try to set the style, is this the appropriate way to do this?

Thanks

Arthur
0
Arthur
Top achievements
Rank 1
answered on 19 Jul 2012, 04:04 PM
Applogies it wouldn't allow me to attach code here is the xaml

<Window x:Class="AsyncValidationWPFExample.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
        Title="MainWindow" Height="350" Width="525">


    <Window.Resources>
        <Style  TargetType="{x:Type telerik:GridViewCell}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type telerik:GridViewCell}">
                        <Grid>
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="SelectionStates">
                                    <VisualState x:Name="Unselected"/>
                                    <VisualState x:Name="Selected">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="Background_Selected">
                                                <DiscreteObjectKeyFrame KeyTime="0">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <Visibility>Visible</Visibility>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Normal"/>
                                    <VisualState x:Name="Current">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="Background_Current">
                                                <DiscreteObjectKeyFrame KeyTime="0">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <Visibility>Visible</Visibility>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="MouseOver">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="Background_Over">
                                                <DiscreteObjectKeyFrame KeyTime="0">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <Visibility>Visible</Visibility>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                                <VisualStateGroup x:Name="EditingStates">
                                    <VisualState x:Name="Edited">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Margin" Storyboard.TargetName="PART_ContentPresenter">
                                                <DiscreteObjectKeyFrame KeyTime="0">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <Thickness>0</Thickness>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="VerticalAlignment" Storyboard.TargetName="PART_ContentPresenter">
                                                <DiscreteObjectKeyFrame KeyTime="0">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <VerticalAlignment>Stretch</VerticalAlignment>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="PART_CellBorder">
                                                <DiscreteObjectKeyFrame KeyTime="0">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <SolidColorBrush Color="White"/>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Display"/>
                                </VisualStateGroup>
                                <VisualStateGroup x:Name="DisabledStates">
                                    <VisualState x:Name="Enabled"/>
                                    <VisualState x:Name="Disabled">
                                        <Storyboard>
                                            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="PART_CellBorder">
                                                <DiscreteDoubleKeyFrame KeyTime="0" Value="0.4"/>
                                            </DoubleAnimationUsingKeyFrames>
                                            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="PART_ContentPresenter">
                                                <DiscreteDoubleKeyFrame KeyTime="0" Value="0.7"/>
                                            </DoubleAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="Background_Disabled">
                                                <DiscreteObjectKeyFrame KeyTime="0">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <Visibility>Visible</Visibility>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                                <VisualStateGroup x:Name="ValueStates">
                                    <VisualState x:Name="CellValid"/>
                                    <VisualState x:Name="CellInvalid">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="Background_Invalid">
                                                <DiscreteObjectKeyFrame KeyTime="0">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <Visibility>Visible</Visibility>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="InvalidUnfocused">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="Background_Invalid_Unfocused">
                                                <DiscreteObjectKeyFrame KeyTime="0">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <Visibility>Visible</Visibility>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <Border x:Name="PART_CellBorder" BorderBrush="{TemplateBinding VerticalGridLinesBrush}" Background="{Binding Background, RelativeSource={RelativeSource TemplatedParent}}">
                                <Border.BorderThickness>
                                    <Binding ConverterParameter="Right" Path="VerticalGridLinesWidth" RelativeSource="{RelativeSource TemplatedParent}">
                                        <Binding.Converter>
                                            <telerik:GridLineWidthToThicknessConverter/>
                                        </Binding.Converter>
                                    </Binding>
                                </Border.BorderThickness>
                            </Border>
                            <Border x:Name="Background_Over" BorderBrush="#FFFFC92B" BorderThickness="1" Grid.ColumnSpan="2" Grid.Column="2" CornerRadius="1" Margin="1,1,2,2" Visibility="Collapsed">
                                <Border BorderBrush="White" BorderThickness="1">
                                    <Border.Background>
                                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                            <GradientStop Color="#FFFFFBA3" Offset="1"/>
                                            <GradientStop Color="#FFFFFBDA" Offset="0"/>
                                        </LinearGradientBrush>
                                    </Border.Background>
                                </Border>
                            </Border>
                            <Border x:Name="Background_Selected" BorderBrush="#FFFFC92B" BorderThickness="1" Grid.ColumnSpan="2" Grid.Column="2" CornerRadius="1" Margin="1,1,2,2" Visibility="Collapsed">
                                <Border BorderBrush="White" BorderThickness="1">
                                    <Border.Background>
                                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                            <GradientStop Color="#FFFCE79F" Offset="1"/>
                                            <GradientStop Color="#FFFDD3A8"/>
                                        </LinearGradientBrush>
                                    </Border.Background>
                                </Border>
                            </Border>
                            <Border x:Name="Background_Current" BorderBrush="#FF848484" BorderThickness="1" Grid.ColumnSpan="2" Grid.Column="2" CornerRadius="1" Margin="1,1,2,2" Visibility="Collapsed"/>
                            <Border x:Name="Background_Invalid" BorderBrush="#FFDB000C" BorderThickness="1" Background="White" Grid.ColumnSpan="2" Grid.Column="2" CornerRadius="1" Margin="1,1,2,2" Visibility="Collapsed">
                                <Border.ToolTip>
                                    <ToolTip x:Name="validationTooltip" Content="{TemplateBinding Errors}" Placement="Right">
                                        <ToolTip.Template>
                                            <ControlTemplate TargetType="{x:Type ToolTip}">
                                                <Grid x:Name="Root" Margin="5,0" Opacity="0" RenderTransformOrigin="0,0">
                                                    <Grid.RenderTransform>
                                                        <TranslateTransform X="-25"/>
                                                    </Grid.RenderTransform>
                                                    <VisualStateManager.VisualStateGroups>
                                                        <VisualStateGroup x:Name="OpenStates">
                                                            <VisualStateGroup.Transitions>
                                                                <VisualTransition From="{x:Null}" GeneratedDuration="0" GeneratedEasingFunction="{x:Null}" Storyboard="{x:Null}" To="{x:Null}"/>
                                                                <VisualTransition From="{x:Null}" GeneratedDuration="0:0:0.2" GeneratedEasingFunction="{x:Null}" To="Open">
                                                                    <Storyboard>
                                                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="X" Storyboard.TargetName="xform">
                                                                            <SplineDoubleKeyFrame KeyTime="0:0:0.2" Value="0"/>
                                                                        </DoubleAnimationUsingKeyFrames>
                                                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="Root">
                                                                            <SplineDoubleKeyFrame KeyTime="0:0:0.2" Value="1"/>
                                                                        </DoubleAnimationUsingKeyFrames>
                                                                    </Storyboard>
                                                                </VisualTransition>
                                                            </VisualStateGroup.Transitions>
                                                            <VisualState x:Name="Closed">
                                                                <Storyboard>
                                                                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="Root">
                                                                        <SplineDoubleKeyFrame KeyTime="0" Value="0"/>
                                                                    </DoubleAnimationUsingKeyFrames>
                                                                </Storyboard>
                                                            </VisualState>
                                                            <VisualState x:Name="Open">
                                                                <Storyboard>
                                                                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="X" Storyboard.TargetName="xform">
                                                                        <SplineDoubleKeyFrame KeyTime="0" Value="0"/>
                                                                    </DoubleAnimationUsingKeyFrames>
                                                                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="Root">
                                                                        <SplineDoubleKeyFrame KeyTime="0" Value="1"/>
                                                                    </DoubleAnimationUsingKeyFrames>
                                                                </Storyboard>
                                                            </VisualState>
                                                        </VisualStateGroup>
                                                    </VisualStateManager.VisualStateGroups>
                                                    <Border Background="#052A2E31" CornerRadius="5" Margin="4,4,-4,-4"/>
                                                    <Border Background="#152A2E31" CornerRadius="4" Margin="3,3,-3,-3"/>
                                                    <Border Background="#252A2E31" CornerRadius="3" Margin="2,2,-2,-2"/>
                                                    <Border Background="#352A2E31" CornerRadius="2" Margin="1,1,-1,-1"/>
                                                    <Border Background="#FFDC000C" CornerRadius="2"/>
                                                    <Border CornerRadius="2">
                                                        <ItemsControl>
                                                            <ItemsControl.ItemsPanel>
                                                                <ItemsPanelTemplate>
                                                                    <StackPanel IsItemsHost="True"/>
                                                                </ItemsPanelTemplate>
                                                            </ItemsControl.ItemsPanel>
                                                            <ItemsControl.ItemTemplate>
                                                                <DataTemplate>
                                                                    <TextBlock Foreground="White" MaxWidth="250" Margin="8,4" TextWrapping="Wrap" Text="This is not being displayed!!!"/>
                                                                </DataTemplate>
                                                            </ItemsControl.ItemTemplate>
                                                        </ItemsControl>
                                                    </Border>
                                                </Grid>
                                            </ControlTemplate>
                                        </ToolTip.Template>
                                    </ToolTip>
                                </Border.ToolTip>
                                <Grid Background="Transparent" HorizontalAlignment="Right" Height="12" Margin="1,-4,-4,0" VerticalAlignment="Top" Width="12">
                                    <Path Data="M1,0L6,0A2,2,90,0,1,8,2L8,7z" Fill="#FFDB000C" Margin="1,3,0,0"/>
                                    <Path Data="M0,0L2,0 8,6 8,8" Fill="White" Margin="1,3,0,0"/>
                                </Grid>
                            </Border>
                            <Border x:Name="Background_Invalid_Unfocused" BorderBrush="#FFCE7D7D" BorderThickness="1" Grid.ColumnSpan="2" Grid.Column="2" CornerRadius="1" Margin="1,1,1,2" Opacity="1" Visibility="Collapsed">
                                <Border BorderThickness="1">
                                    <Border.BorderBrush>
                                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                            <GradientStop Color="#FFEBF4FD"/>
                                            <GradientStop Color="#FFDBEAFD" Offset="1"/>
                                        </LinearGradientBrush>
                                    </Border.BorderBrush>
                                    <Border.Background>
                                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                            <GradientStop Color="#FFFCDCDC"/>
                                            <GradientStop Color="#FFFCC1C1" Offset="1"/>
                                        </LinearGradientBrush>
                                    </Border.Background>
                                </Border>
                            </Border>
                            <Border x:Name="Background_Disabled" BorderBrush="#FFF8F8F8" BorderThickness="1" Background="#FFE0E0E0" Grid.ColumnSpan="2" Grid.Column="2" Margin="0,0,1,1" Visibility="Collapsed"/>
                            <ContentPresenter x:Name="PART_ContentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="Padding" Value="5,0,3,0"/>
            <Setter Property="BorderBrush" Value="#FFCBCBCB"/>
            <Setter Property="BorderThickness" Value="0,0,1,0"/>
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="SnapsToDevicePixels" Value="True"/>
            <Setter Property="FocusVisualStyle">
                <Setter.Value>
                    <Style>
                        <Setter Property="Control.Template">
                            <Setter.Value>
                                <ControlTemplate>
                                    <Border BorderBrush="#FF848484" BorderThickness="1" CornerRadius="1" Margin="1,1,2,2"/>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>


    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="30" />
        </Grid.RowDefinitions>
        <telerik:RadGridView x:Name="radGridView" AutoGenerateColumns="False">
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding FirstName}" Header="First Name" />
                <telerik:GridViewDataColumn DataMemberBinding="{Binding LastName}" Header="Last Name" />
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Age}" Header="Age" />
                <telerik:GridViewDataColumn DataMemberBinding="{Binding BirthDay}" Header="Birth Day" />
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>
    </Grid>
</Window>
0
Vanya Pavlova
Telerik team
answered on 24 Jul 2012, 11:27 AM
Hello Arthur,

 


Generally you are on the right way! The predefined cell style will work if you perform the validation in view mode and the changes will be visible there. If you perform the validation in edit mode you have to predefine the behavior of the GridViewEditorPresenter and the elements contained in it.  You have defined an implicit style targeted at GridViewCell, which will affect all GridViewCells. Also you may set an explicit cell style through setting CellStyle property of the column.   




All the best,
Vanya Pavlova
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Arthur
Top achievements
Rank 1
answered on 27 Jul 2012, 09:58 AM
Vanya, 

I am seeing different behaviour here depending on the validation method NOT just whether validation occurs in view or edit mode.

I have taken the telerk sample code 258779_355701-Popup which uses the GridViewEditorPresenter to style when the cellvalidating event is used.

Here I have successfully been able to change the validation style.

If I now  utilise IDataErrorInfo (but the same GridViewEditorPresenter) then the styling is completely different.

So how should I style the validation when using IDataErrorInfo in edit mode??

Thanks in advance
0
Vanya Pavlova
Telerik team
answered on 27 Jul 2012, 10:08 AM
Hello Arthur,

 

When you implement this interface you will see the Border, which comes from the TextBox control. 
Have you tried to predefine the ValidationToolTip of the TextBox itself when you implement IDataErrorInfo interface? 



Kind regards,
Vanya Pavlova
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Arthur
Top achievements
Rank 1
answered on 27 Jul 2012, 10:22 AM
Hi Vanya,

I am a little confused. From you previous post is appeared that in edit mode the GridViewPresenter styling method should work? Are you saying that if I use IDataErrorInfo I need  to style differently?

I will look at the styling of the text box as you suggest.However, I don't understand why I need to do this for one validation type rather than the other

Please could you clarify this for me

Many thanks

Arthur
0
Vanya Pavlova
Telerik team
answered on 27 Jul 2012, 10:44 AM
Hello Arthur,

 

I believe that the following forum thread "IDataErrorInfo and tooltip" will answer to your questions. 



Kind regards,
Vanya Pavlova
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Arthur
Top achievements
Rank 1
answered on 27 Jul 2012, 10:53 AM
OK thanks Vanya,

Have a great weekend!
Tags
GridView
Asked by
Arthur
Top achievements
Rank 1
Answers by
Nedyalko Nikolov
Telerik team
Arthur
Top achievements
Rank 1
Vanya Pavlova
Telerik team
Share this question
or