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

Having trouble with the validation of cells

3 Answers 59 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Nicklas
Top achievements
Rank 1
Nicklas asked on 07 May 2013, 08:09 AM
I seem to have run into some trouble with the validation of a cell in my GridView. Should this control automatically validate on exceptions? It still does so, even after removing the validation tags from my xaml.

Anyway, my actual issue is that whenever I want to add a new row and then click cancel before editing any of the cells, the validation occurs, thus not letting me delete the row or cancel the operation (with a cancel button doint rejectchanges) before I enter an actual value and the validation of the field is ok.
Here's the grid (I've just renamed some elements to "XX" before pasting this):
<telerik:RadGridView x:Name="ToolStringView"
                 ItemsSource="{Binding Path=SelectedRun.ToolStringInfo, Mode=TwoWay}" IsEnabled="{Binding ElementName=runPage, Path=HasWritePermission}"
                 Margin="20,20,40,0" Width="450" MinHeight="300" MaxHeight="500" FontFamily="Segoe UI" FontSize="14"
                 CanUserFreezeColumns="False" RowIndicatorVisibility="Collapsed" telerik:StyleManager.Theme="Metro"
                 ShowGroupPanel="False" ShowInsertRow="True" IsFilteringAllowed="False" AutoGenerateColumns="False">
    <telerik:RadGridView.Columns>
        <telerik:GridViewColumn Width="30">
            <telerik:GridViewColumn.CellTemplate>
                <DataTemplate>
                    <XX_Silverlight_Library_Controls:DeleteButton
                    Width="20" Height="20"
                    telerik:StyleManager.Theme="Metro" FontFamily="Segoe UI" FontSize="14"
                        Command="{Binding DeleteToolStringInfoCommand, Source={StaticResource runViewModel}}"
                        CommandParameter="{Binding}"/>
                </DataTemplate>
            </telerik:GridViewColumn.CellTemplate>
        </telerik:GridViewColumn>
          
        <telerik:GridViewDataColumn Header="Name" DataMemberBinding="{Binding Name}" Width="*"/>
  
        <telerik:GridViewDataColumn DataMemberBinding="{Binding Depth, Mode=TwoWay}" Header="Depth" MinWidth="100" Width="*">
            <telerik:GridViewDataColumn.CellTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <StackPanel.Resources>
                            <XX_Silverlight_Library_Util:XXValueConverter  x:Name="RunViewValueConverter" ConvertTo="{Binding Source={StaticResource runViewModel}, Path=Range.CurrentUnit}"/>
                        </StackPanel.Resources>
                        <XX_Silverlight_Library_Controls:XXNumericControl Width="150"
                                    NumericValue="{Binding Depth, Mode=TwoWay, Converter={StaticResource RunViewValueConverter}}"                                         
                                    FontFamily="Segoe UI" FontSize="14"
                                    telerik:StyleManager.Theme="Metro">
                        </XX_Silverlight_Library_Controls:XXNumericControl>
                        <TextBlock Text="{Binding Path=UnitLabel, ElementName=RunViewValueConverter, FallbackValue=NA}" FontFamily="Segoe UI" FontSize="14" VerticalAlignment="Bottom" Margin="0,0,0,3" Width="50"/>
                    </StackPanel>
                </DataTemplate>
            </telerik:GridViewDataColumn.CellTemplate>
            <telerik:GridViewDataColumn.CellEditTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <StackPanel.Resources>
                            <XX_Silverlight_Library_Util:XXValueConverter  x:Name="RunViewValueConverter" ConvertTo="{Binding Source={StaticResource runViewModel}, Path=Range.CurrentUnit}"/>
                        </StackPanel.Resources>
                        <XX_Silverlight_Library_Controls:XXNumericControl Width="150"
                                    NumericValue="{Binding Depth, Mode=TwoWay, Converter={StaticResource RunViewValueConverter}}"
                                    FontFamily="Segoe UI" FontSize="14"
                                    telerik:StyleManager.Theme="Metro">
                        </XX_Silverlight_Library_Controls:XXNumericControl>
                        <TextBlock Text="{Binding Path=UnitLabel, ElementName=RunViewValueConverter, FallbackValue=NA}" FontFamily="Segoe UI" FontSize="14" VerticalAlignment="Bottom" Margin="0,0,0,3" Width="50"/>
                    </StackPanel>
                </DataTemplate>
            </telerik:GridViewDataColumn.CellEditTemplate>
        </telerik:GridViewDataColumn>
  
  
    </telerik:RadGridView.Columns>
    <i:Interaction.Behaviors >
        <XX_Silverlight_Library_Controls_Keyboard_Behaviors:ShowKeyboardBehavior></XX_Silverlight_Library_Controls_Keyboard_Behaviors:ShowKeyboardBehavior>
    </i:Interaction.Behaviors>
</telerik:RadGridView>

The problem here being that the cells in the "Name" column seems to validate no matter if "ValidatesOnExceptions=true" is set in the XAML or not.
Is there a workaround or solution to this, letting me delete the row either without the validation occurring or with the validation still being active (I.e red border around the cell)?

I should also mention that the 'ToolStringInfo' class is an entity class (EntityFramework) set to ne "not null" in the database.

3 Answers, 1 is accepted

Sort by
0
Nedyalko Nikolov
Telerik team
answered on 09 May 2013, 02:23 PM
Hi,

Can you try setting radGridView.ValidatesOnDataErrors property to "InEditMode" and let me know about the result.
You can set this property on a column level too.

Kind regards,
Nedyalko Nikolov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Nicklas
Top achievements
Rank 1
answered on 10 May 2013, 08:16 AM
Hi Nedyalko,

Thanks for you suggestion. However, I've tried it and it does not seem work enabling the suggested property.

I've tried several different validation combinations, but like I said, it seems to validate anyway. (Without disabling it of course)

A theory I have suggests that whenever I click to add a new row in the grid, the first cell is always selected by default, thus triggering the validationexception. I was able to work around this by selecting another cell like this:
private void ToolStringView_OnDataLoaded(object sender, EventArgs e)
{
    Dispatcher.BeginInvoke(new Action(() =>
        {
            ToolStringView.CurrentCellInfo = new GridViewCellInfo(ToolStringView.Items[2], ToolStringView.Columns["Depth"]);
            ToolStringView.Focus();
        }));
}

This at least selects another cell, but the validation still remains and gets triggered whenever I click the delete button on the row in question. 
0
Nedyalko Nikolov
Telerik team
answered on 10 May 2013, 02:03 PM
Hi,

Could you please send me a sample project which I can debug on my side in order to see what is going on?
Thank you in advance.

All the best,
Nedyalko Nikolov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

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