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

Infinite Loop when Validating

5 Answers 132 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Bill
Top achievements
Rank 1
Bill asked on 08 May 2009, 07:48 PM
I have a strange problem.  In the below code when conditions exist that causes one of the messages to be displayed, after the message is acknowledged (stepping this through) the validate is immediately called again.  If I remove the messages, then this behavior is not exhibited.  Am I doing something wrong, or is this a bug.  I'm running the latest of the lastest.

private
void grdSleeves_Validating(object sender, CancelEventArgs e)

{

 

    try

 

    {

 

        if (sender is RadGridView)

 

        {

 

            RadGridView grid = (RadGridView)sender;

 

 

            if (grid.CurrentCell.ColumnIndex == (int)enum_grid_sleeve.picked)

 

            {

 

                int picked = Convert.ToInt32(grid.ActiveEditor.Value);

 

 

                int available = Convert.ToInt32(grid.CurrentRow.Cells[(int)enum_grid_sleeve.paqavailable].Value);

 

 

                int required = Convert.ToInt32(grid.CurrentRow.Cells[(int)enum_grid_sleeve.paq].Value);

 

 

                if (available < picked) { e.Cancel = true; MessageBox.Show("Picking more than available."); }

 

 

                else if (required < picked) {e.Cancel = true; MessageBox.Show("Picking more than required."); }

 

            }

        }

    }

 

    catch { }

 

}

5 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 11 May 2009, 09:42 AM
Hello Bill,

I tested the code. It seems to be working with my test project. Maybe there is something in your application that affects the validation process. Could you please open a support ticket and send us the code for your application. We will investigate the issue in detail and find a proper solution.

I am looking forward to your reply.

Best wishes,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Bill
Top achievements
Rank 1
answered on 11 May 2009, 03:56 PM
Jack, thanks for your quick response.

The problem is easy to duplicate, but I left out a detail.  The form that is causing the loop is a MDI Child form.  So if you add this to the mixture, you'll see the problem

Bill
0
Jack
Telerik team
answered on 12 May 2009, 03:14 PM
Hello Bill,

Thank you for the additional info.

Now I reproduced the issue, although I am not yet sure whether this is a RadGridView issue. We will research the case and will consider addressing the issue in one of our upcoming releases.

You could use a flag property to workaround it. Take a look at the sample below:

bool validating = false
 
void radGridView1_Validating(object sender, CancelEventArgs e) 
    try 
    { 
        if (!validating) 
        { 
            validating = true
            if (sender is RadGridView) 
            { 
                RadGridView grid = (RadGridView)sender; 
                if (grid.IsInEditMode && grid.CurrentCell.ColumnIndex == 2) 
                { 
                    int picked = Convert.ToInt32(grid.ActiveEditor.Value); 
                    int available = Convert.ToInt32(grid.CurrentRow.Cells[2].Value); 
                    int required = Convert.ToInt32(grid.CurrentRow.Cells[2].Value); 
                    e.Cancel = true
                    MessageBox.Show("Picking more than available."); 
                } 
            } 
            validating = false
        } 
    } 
    catch { } 

Should you have any questions, I will be glad to help.

Regards,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Bill
Top achievements
Rank 1
answered on 12 May 2009, 03:51 PM
That does stop the loop, but why doesn't it restore the original value when the validation fails and the cancel flag is set.
0
Jack
Telerik team
answered on 13 May 2009, 08:19 AM
Hello Bill,

I haven't noticed this issue because I used numeric columns in my test. This issue is specific to the text column; thank you for reporting it. You can work around the issue by setting the old value explicitly. Please see the sample:

void radGridView1_Validating(object sender, CancelEventArgs e) 
    try 
    { 
        if (!validating) 
        { 
            validating = true
            if (sender is RadGridView) 
            { 
                RadGridView grid = (RadGridView)sender; 
                if (grid.IsInEditMode && grid.CurrentCell.ColumnIndex == 1) 
                { 
                    e.Cancel = true
                    this.radGridView1.ActiveEditor.Value = this.radGridView1.CurrentCell.Value; 
                    MessageBox.Show("Picking more than available."); 
                } 
            } 
            validating = false
        } 
    } 
    catch { }  

Don't hesitate to write us if you have any other questions.

Best wishes,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
GridView
Asked by
Bill
Top achievements
Rank 1
Answers by
Jack
Telerik team
Bill
Top achievements
Rank 1
Share this question
or