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

[Solved] Grid validation can cause hang

4 Answers 160 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Edward
Top achievements
Rank 1
Edward asked on 14 Dec 2010, 04:09 PM
Hello,

In our application, we have several grids on one page, many of which have ShowInsertRow=True and a handler for the RowValidating event to implement row validation.

Suppose we click on grid 1's "click here to insert data" row, and try to enter some invalid data - the red exclamation mark appears as expected. If we now click on grid 2's "click here to insert data" row without fixing the invalid row in grid 1, the row in grid 1 is not cancelled. Instead the row in grid 2 is committed immediately, and it too now displays a red exclamation mark in the row header (because an empty row is invalid for us). The application has now hung - we cannot click anywhere in either grid and CPU has risen to 100%.

There is a similar issue with property validation, although instead of the application hanging, both grid 1 and grid 2 try to display their validation error simultaneously (resulting in a flickering effect).

Here is some test code that reproduces the problem. The XAML is simply:

<telerik:RadGridView Grid.Row="0" Name="radGridView1" Width="400" ShowGroupPanel="False" ShowInsertRow="True" AddingNewDataItem="radGridView_AddingNewDataItem" RowValidating="radGridView_RowValidating"/>
<telerik:RadGridView Grid.Row="1" Name="radGridView2" Width="400" ShowGroupPanel="False" ShowInsertRow="True" AddingNewDataItem="radGridView_AddingNewDataItem" RowValidating="radGridView_RowValidating"/>

And the code behind:

public partial class MainPage : UserControl
{
    public MainPage()
    {
        InitializeComponent();
        SetUpGrids();
    }
 
    public void SetUpGrids()
    {
        this.radGridView1.ItemsSource = new ObservableCollection<Item>();
        this.radGridView2.ItemsSource = new ObservableCollection<Item>();
    }
 
    private void radGridView_AddingNewDataItem(object sender, GridViewAddingNewEventArgs e)
    {
        e.NewObject = new Item();
    }
 
    private void radGridView_RowValidating(object sender, GridViewRowValidatingEventArgs e)
    {
        Item entity = e.Row.DataContext as Item;
        if (entity != null && string.IsNullOrWhiteSpace(entity.Description))
        {
            var validationResult = new GridViewCellValidationResult();
            validationResult.ErrorMessage = "Please enter a description.";
            e.ValidationResults.Add(validationResult);
            e.IsValid = false;
        }
    }
}

And the Item class is simply:

public class Item
{
    public string Description { get; set; }
}

Many thanks

Ed

4 Answers, 1 is accepted

Sort by
0
Edward
Top achievements
Rank 1
answered on 14 Dec 2010, 04:23 PM
Just to be clear, I think the bug is that if you enter any invalid data into grid 1, and click on the "click here to add new item" row in grid 2, then grid 2 unexpectedly commits a new row. What happens after that depends on what the validation is set up to do.

Ed
0
Veselin Vasilev
Telerik team
answered on 14 Dec 2010, 04:34 PM
Hi Edward,

Please try setting the ActionOnLostFocus="None" property of RadGridView.
By default it is set to CommitChanges.


Regards,
Veselin Vasilev
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Edward
Top achievements
Rank 1
answered on 14 Dec 2010, 05:22 PM
Thanks, but we do want changes to be committed when the grid loses focus. So the bug seems to be that the wrong grid's changes are committed (grid 2 instead of grid 1).

Ed
0
Veselin Vasilev
Telerik team
answered on 20 Dec 2010, 01:31 PM
Hello Edward,

The possible solution then would be to use asynchronous validation as demonstrated here.

Regards,
Veselin Vasilev
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
Tags
GridView
Asked by
Edward
Top achievements
Rank 1
Answers by
Edward
Top achievements
Rank 1
Veselin Vasilev
Telerik team
Share this question
or