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

Validating event shows old cell value

5 Answers 253 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Tariq
Top achievements
Rank 1
Tariq asked on 02 Jan 2009, 11:54 AM
I want to validate the current cell before the user moves away. To achieve this I am using the Validating event of the GridView.  However when I check the value of the current cell (radGridView1.CurrentCell.Value) it shows the cell's old value which is useless for validation. I want to get hold of the new value.

I did some experiments with ValueChanging event  but it fires upon every keypress and therefore cannot be effectively used.

I simply want to validate the text of a cell before the user is allowed to move away.

Tariq Changgez

5 Answers, 1 is accepted

Sort by
0
Deyan
Telerik team
answered on 05 Jan 2009, 02:53 PM
Hi Tariq,

Thank you for your question.

It is correct to use the Validating event of the RadGridView control. In order to access the new input value however, you should use the RadGridView.ActiveEditor.Value property:

private void On_Validating(object sender, CancelEventArgs e) 
            int input; 
 
            if (this.radGridView1.ActiveEditor.IsModified && !Int32.TryParse(this.radGridView1.ActiveEditor.Value.ToString(), out input)) 
            { 
                e.Cancel = true;  
            } 
 } 

Since the Validating event is called also when the Form closes, I check whether its value has been modified in order to be sure that I can access it.

This code snippet demonstrates how to check whether the user has typed an integer. If not, the old value of the cell is restored.

I hope this helps.

Do not hesitate to write back if you need further assistance.

Best wishes,
Deyan
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Tariq
Top achievements
Rank 1
answered on 06 Jan 2009, 12:01 PM
Thanks, the validation is now working. However, if the user has entered an invalid value, the Editor gets closed and the user has to click at the field again to start new editor mode. Is there a way that upon invalid data, the control goes back to the same cell and opens the editor by itself.

Tariq Changgez
0
Deyan
Telerik team
answered on 09 Jan 2009, 09:02 AM
Hello Tariq,

Thanks for your question.

RadGridView does not support the described behavior yet. We are working on this and will try to implement it for the Q3 2008 SP2, but since the release date is close, I cannot confirm it.

There is a way to prevent the user from typing invalid values, however. You can implement an Editor Form that pops up each time the user wants to edit a row and validates the input according to your preferences.

I am attaching a sample project with a RadGridView that uses an Editor Form which is shown to the users whenever they want to edit a row. The data validation is not implemented here but the idea is clear - you can keep the Editor Form shown until the user enters the correct data.

I hope this helps.

Do not hesitate to write back if you need further assistance.

All the best,
Deyan
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Bill
Top achievements
Rank 1
answered on 10 Apr 2009, 12:25 AM
Has this been resolved yet?  If it can't validate then we miss out on the benefits of an editable grid.

I have a grid with an editable text box cell. I need to be able to stay there until the user enters some valid data (according to whatever validation methods I choose to code).  We chose editable grids to avoid popups  so I'm hoping you have a fix ? ? ?

Thanks.
0
Deyan
Telerik team
answered on 13 Apr 2009, 11:28 AM
Hi Bill,

I am happy to inform you that this issue has been addressed in Q1 2009 release of RadControls for WinForms. You can use the Validating event of the RadGridView which provides the possibility to check the current value within a cell and provide custom validation. The CancelEventArgs object gives you the opportunity to cancel the newly typed value and thus prevent the user from leaving the editor of the cell.

I hope this is helpful.

Kind regards,
Deyan
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Tags
GridView
Asked by
Tariq
Top achievements
Rank 1
Answers by
Deyan
Telerik team
Tariq
Top achievements
Rank 1
Bill
Top achievements
Rank 1
Share this question
or