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

Infinite loop 2 RadGridViews while row validation

6 Answers 192 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 13 Aug 2012, 02:22 AM
Hi,

I have 2 RadGridView's in a window both of which perform row level validation.  I am able to raise an exception" "An infinite loop appears to have resulted from cross-dependent views." when both grids are validating. 

Ive created a very basic test app and here are the steps:
  1. Top Grid.  Click "Click here to add a new item" to add a new row.
  2. Bottom Grid do the same.

     

    The Top grid will show the row as invalid. and the botton grid will have a new row
  3. Click in the bottom grid's new row (the Initial value 2 column) and it will crash

Here is the Xaml

<Window x:Class="TestMultipleRadGrids.MainWindow"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
         
        <telerik:RadGridView Grid.Row="0"
                             x:Name="_rad1"
                             ValidatesOnDataErrors="InEditMode"
                             ShowGroupPanel="False" 
                             AutoGenerateColumns="False"
                             CanUserReorderColumns="True"
                             CanUserInsertRows="True"
                             RowValidating="_rad1_RowValidating"
                             ShowInsertRow="True">
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn Header="Name1" />
                <telerik:GridViewDataColumn Header="Initial Value1" DataMemberBinding="{Binding InitialValue1, Mode=TwoWay}"/>
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>
 
        <telerik:RadGridView Grid.Row="1"
                             x:Name="_rad2"
                             ShowGroupPanel="False" 
                             ValidatesOnDataErrors="InEditMode"
                             AutoGenerateColumns="False"
                             CanUserReorderColumns="True"
                             CanUserInsertRows="true"
                             RowValidating="_rad2_RowValidating"
                             ShowInsertRow="True">
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn Header="Name2"/>
                <telerik:GridViewDataColumn Header="Initial Value2" DataMemberBinding="{Binding InitialValue2, Mode=TwoWay}" />
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>
    </Grid>
</Window>


Here is the code behind:

using System.Windows;
using Telerik.Windows.Controls;
 
namespace TestMultipleRadGrids
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
 
        private void _rad1_RowValidating(object sender, Telerik.Windows.Controls.GridViewRowValidatingEventArgs e)
        {
            GridViewCellValidationResult validationResult = new GridViewCellValidationResult();
            validationResult.PropertyName = "InitialValue1";
            validationResult.ErrorMessage = "Error";
            e.ValidationResults.Add(validationResult);
            e.IsValid = false;
        }
 
        private void _rad2_RowValidating(object sender, Telerik.Windows.Controls.GridViewRowValidatingEventArgs e)
        {
            _rad1.Focus();
 
            GridViewCellValidationResult validationResult = new GridViewCellValidationResult();
            validationResult.PropertyName = "InitialValue2";
            validationResult.ErrorMessage = "Error";
            e.ValidationResults.Add(validationResult);
            e.IsValid = false;
        }
    }
}


Any help would be greatly appreciated.

6 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 15 Aug 2012, 10:06 AM
Hello Chris,

That would be a kind of expected behavior since once you perform the validation for the first grid, the validation for the second is fired and vice versus. Why do you need to perform it in such manner ? Do you want to validate only a single item (placed in the two grids) or you have more complicated scenario ? Why not performing the validation at property level for example ? Do you require some of the properties displayed in the first grid and the others - in the second one ? 

Kind regards,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Chris
Top achievements
Rank 1
answered on 16 Aug 2012, 12:07 AM
This was only an example demonstrating the undesired behaviour.

What I really have are 2 user controls (with a RadGridView in each) and these bind to 2 seperate objects.
So both grids work on different data in their own user control but happen to be in the same window.

Problem is I cant have 2 RadGrids performing row level validation even if they are in a user control!

As for the property level validation: Its only good for cell level validation. In my case I need row level validation as I need the user to "complete" the row and validate at the end so I can then construct an object. The validation of individual cells dont make any sense in my case!

Basically this control provides a GridValidating event and it gets tangled!  Either I am using it incorrectly and I need some help or there is a bug that needs to be addressed:)

Even a work around would be appreciated.



0
Chris
Top achievements
Rank 1
answered on 16 Aug 2012, 02:27 AM
I think I have managed to work round the problem by not being so severe in the validation checks but I believe a problem exists at your end.


When a cell is marked as invalid (in my case the validation error is set for a property) all controls on the page such as text boxes and combos seem to be disabled and focus remains in the cell with the error which is great. But have another grid on the page it cells are not disabled and so its validation can also fire! When it does fire it tries to do the same as the first grid and the cell in error (for each grid) fight over focus constantly triggering the validation event and hence an exception is raised!

I really dont need the grid to be so brutal and try and lock the focus into a cell and can this behaviour be changed?

0
Maya
Telerik team
answered on 20 Aug 2012, 03:08 PM
Hi Chris,

Indeed, the invalid row gets the focus and does not release it until correct value is inserted. What you can try is to set ActionOnLostFocus to "None" (the default value is "CommitEdit" and that is why it keeps constantly the focus as it tries to commit). Furthermore, you can try performing asynchronous validation as illustrated in this blog post.

Regards,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Brian
Top achievements
Rank 1
answered on 12 Jul 2017, 05:21 PM

I had the exact same problem and a search led me to this page that didn't really have any solutions. Fortunately someone else on my team found a solution, so I thought I'd post it here to help anyone else who finds this page. All we had to do was set:

ValidatesOnDataErrors="InViewMode"

 

Now I click click the "Add new item" line in multiple RadGridView and don't have the problems with the lockup, but the data still gets validates and shows the errors.

0
Martin Ivanov
Telerik team
answered on 17 Jul 2017, 09:26 AM
Hello Brian,

Thank you for sharing your solution here.

If you still has issues on your side, may I ask you to prepare some runnable code along with steps to reproduce the errors, and send it over? 

Regards,
Martin Ivanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
GridView
Asked by
Chris
Top achievements
Rank 1
Answers by
Maya
Telerik team
Chris
Top achievements
Rank 1
Brian
Top achievements
Rank 1
Martin Ivanov
Telerik team
Share this question
or