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

Invalid values in the GridViewDataErrorEventArgs object

1 Answer 55 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Roger Abderhalden
Top achievements
Rank 1
Roger Abderhalden asked on 05 Nov 2009, 02:25 PM
Hello

Currently I have the following problem: In my solution there is a radgridview object bound to a MS SQL table containing one string field, three numeric fields and one boolean field. None of these fields are allowed to be NULL. If I click on "new row" the editor of the first field opens correctly. Now if I click to another row in the table the grid raises the DataError event because the field values are not set. So far, so good.

In my event handler I want to check if all values are empty and then cancel the "add new row" process. So I want to check the values of the problem line by using GridViewDataRowInfo myRow = radGrid.Rows[e.RowIndex] and then loop over all cell values.
But when the event is raised I get e.RowIndex=0 and e.ColumnIndex=-1. RowIndex points to the first existing row in the table but this is not the problem line. Also the columnindex points not to the problem field.

Do I do a mistake by checking RowIndex/ColumnIndex for a new row?

I use Q2/2009 of the telerik suite.

Any ideas or better solutions to solve this problem are welcome.

Kind regards
Roger

1 Answer, 1 is accepted

Sort by
0
Martin Vasilev
Telerik team
answered on 11 Nov 2009, 02:20 PM
Hello Roger Abderhalden,

Thank you for the question.

If you want to prevent the empty cell from being confirmed, you can use CellValidating event. Please consider using the following code block:
void radGridView1_CellValidating(object sender, CellValidatingEventArgs e)
{
    if (this.radGridView1.IsInEditMode && (e.Value == null || e.Value.ToString() == String.Empty))
    {
        e.Cancel = true;
    }
}

Let me know if this does not suite to your scenario.

Kind regards,
Martin Vasilev
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
Roger Abderhalden
Top achievements
Rank 1
Answers by
Martin Vasilev
Telerik team
Share this question
or