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

radgridview cell validation

2 Answers 132 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Allwin
Top achievements
Rank 1
Allwin asked on 28 Feb 2011, 11:54 PM
Hi

           I am used radgridview in my vb.net project. Here i validate the a particular cell which is only acceptable numeric letters and point separators. The particular cell is in edit mode. How its to validate using vb language.

Please send any sample vb.net project attached for my reference.

Thanks
Allwin
 

2 Answers, 1 is accepted

Sort by
0
Emanuel Varga
Top achievements
Rank 1
answered on 01 Mar 2011, 09:30 AM
Hello Allwin,

If you want to do this on validation you can just try to convert the cell value to a number format (int, float, decimal and so on).
If the conversion fails then it's not a number, like so:
void radGridView1_CellValidating(object sender, CellValidatingEventArgs e)
{
    if (e.Column.FieldName == "TheFieldToBeValidated")
    {
        var value = 0;
        e.Cancel = !(int.TryParse(e.Value.ToString(), out value));
    }
}

Here you are basically stating that if conversion of the value to int fails, then cancel the validation.

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
Telerik WinForms MVP
0
Richard Slade
Top achievements
Rank 2
answered on 01 Mar 2011, 11:15 AM
Hello Allwin,

In addition to Emanuel's suggestion, you may also want to have a look at this blog post  and this code library article on implementing IDataErrorInfo in RadGridView.

Hope that helps but let me know if you have any questions
Richard
Tags
GridView
Asked by
Allwin
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Richard Slade
Top achievements
Rank 2
Share this question
or