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

How to validate row data

3 Answers 220 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Shamjith
Top achievements
Rank 1
Shamjith asked on 18 Dec 2009, 02:58 PM
Hi,
     I have a rad gridview windows control with a GridViewTextBoxColumn and a GridViewCheckBoxColumn. AllowAddNewRow is set to "True" for the Gridview. I have written code in DefaultValuesNeeded event to set the check box selected. I need to validate data in the current editing row before the focus moves to a new row or some other row. I have written code in CurrentRowChanging event to validate the data but the cell value is always null.
 private void radGridView1_CurrentRowChanging(object sender, CurrentRowChangingEventArgs e)  
        {  
            if (e.CurrentRow == null) return;  
 
            radGridView1.Invalidate();  
 
            var val = Convert.ToString(e.CurrentRow.Cells["column1"].Value);  
            if (val == "test")  
            {  
                MessageBox.Show("Invalid data");  
                e.Cancel = true;  
            }  
        } 
In which event should i write the code.

Regards
Shamjith

3 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 19 Dec 2009, 08:48 AM
Hi Shamjith,

You should use RowValidating event in this case. Here is the modified code:

void radGridView1_RowValidating(object sender, RowValidatingEventArgs e)
{
    if (e.Row == null) { return; }
 
    var val = Convert.ToString(e.Row.Cells["Name"].Value);
    if (val == "test")
    {
        MessageBox.Show("Invalid data");
        e.Cancel = true;
    
}

There is an example in our Demo application that demonstrates data validation. It is located under "GridView -> Validation".  Check it for more information.

Sincerely yours,

Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Shamjith
Top achievements
Rank 1
answered on 21 Dec 2009, 09:28 AM
Hi,
    Thank you Jack. We are using rad controls for winforms q3 2008 sp2 version of telerik. We could not find a RowValidating event in this version. Please suggest the alternative in this version.

Regards
Shamjith
0
Nick
Telerik team
answered on 21 Dec 2009, 10:27 AM
Hello Shamjith,

Thank you for contacting us.

The version that you use do not provide such an event and it is really hard to think of some work-around in this case. Please upgrade to our latest release; We are ready to help you in the process. 

Kind regards,
Nick
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
Shamjith
Top achievements
Rank 1
Answers by
Jack
Telerik team
Shamjith
Top achievements
Rank 1
Nick
Telerik team
Share this question
or