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

Validation of data

3 Answers 155 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Eric
Top achievements
Rank 1
Eric asked on 07 Aug 2008, 01:20 PM
What I am trying to do would be to either when the user is leaving the cell or when the user is leaving the row I want to validate the data entered and if they fail the validation then to not allow the user to leave either the cell or row.  I would like to be able to pop a message and inform the user of the error and then set the cursor to when the error exists. 

Is this possible?

3 Answers, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 08 Aug 2008, 01:45 PM
Hi Eric,

You should use RadGridView.Validating event, which fires every time an editor is closing. However, currently there are several serious issues regarding validation of data, which does not prevent from leaving the cell. We will fix these problems for the upcoming Q2 2008 SP1 release (expected by the and of the month). I tried to find a workaround that you could use as a temporary solution and I came up to the following using CurrentCellChanged:

    private GridDataCellElement previousCell;  
        private void radGridView1_CurrentCellChanged(object sender, CurrentCellChangedEventArgs e)  
        {  
            if (previousCell != null &&  
                previousCell.ColumnIndex == 1 &&  
                previousCell.Value != null &&  
                previousCell.Value.ToString() == "aaa")  
            {  
                radGridView1.CurrentRow = radGridView1.Rows[previousCell.RowIndex];  
                radGridView1.CurrentColumn = radGridView1.Columns[previousCell.ColumnIndex];  
            }  
            previousCell = radGridView1.CurrentCell;  
        } 
This code validates values in the second column (with index 1) to be different than certain string.

Please try this solution and tell us if it works fine for you!

We're sorry for the inconvenience caused.


All the best,
Georgi
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Mario
Top achievements
Rank 1
answered on 19 Sep 2008, 10:54 PM
Excuse me, I'm trying to implement something similar but on VB.NET (2005)
Do you have this code for vb?


    
0
Martin Vasilev
Telerik team
answered on 23 Sep 2008, 01:33 PM
Hi Mario,

Thank you for writing.

Please feel free to use our code converter to convert any C# code to VB.Net: http://codechanger.com/
Here is the result of using it on code-block from previous message:
 
Private previousCell As GridDataCellElement 
Private Sub radGridView1_CurrentCellChanged(ByVal sender As ObjectByVal e As CurrentCellChangedEventArgs) 
    If previousCell <> Nothing AndAlso previousCell.ColumnIndex = 1 AndAlso previousCell.Value <> Nothing AndAlso previousCell.Value.ToString() = "aaa" Then 
        radGridView1.CurrentRow = radGridView1.Rows(previousCell.RowIndex) 
        radGridView1.CurrentColumn = radGridView1.Columns(previousCell.ColumnIndex) 
    End If 
    previousCell = radGridView1.CurrentCell 
End Sub 

If you have other questions, do not hesitate to contact me again.

 
Sincerely yours,
Martin Vasilev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
GridView
Asked by
Eric
Top achievements
Rank 1
Answers by
Georgi
Telerik team
Mario
Top achievements
Rank 1
Martin Vasilev
Telerik team
Share this question
or