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

DataError handling with RadGridView

1 Answer 451 Views
GridView
This is a migrated thread and some comments may be shown as answers.
m
Top achievements
Rank 1
m asked on 29 Jul 2011, 09:12 AM
Hello

I am working with a databound RadGridView, I would like to intercept data exceptions errors while editing but also while adding a record. At the moment Im more concerned with adding. While adding if the DataError method is called the ErrorText is set for the row, but instead of staying focused in the current cell, it deletes all data in all cells that were entered. There is an exclamation icon set in the first column of the grid when the ErrorText is set but it is overlapping the current icon.

Isnt the e.Cancel = true line supposed to cancel validation and keep the focus in the current cell till valid data is entered?

private void radGridView1_DataError(object sender, GridViewDataErrorEventArgs e)
{
    e.Cancel = false;
    if ((e.Exception) is System.Data.NoNullAllowedException)
    {
        RadGridView view = (RadGridView)sender;
        if (view.CurrentRow is GridViewNewRowInfo)
        {
            view.CurrentRow.ErrorText = e.Exception.Message;
//The following line doesnt work when adding a row, as e.RowIndex will equal -1
//(sender as RadGridView).Rows[e.RowIndex].ErrorText = e.Exception.Message;         
            e.ThrowException = false;        
        }
    }
}

Could you provide me with a way to retain all data that was entered into the row before the error. Also to some method of indicating which cell has the error, and also how to shut off that exclamation icon when the ErrorText is set or have it be the only icon showing?

Attached are pictures to illustrate how the icon is appearing within the row and showing the tooltip with the empty record

1 Answer, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 03 Aug 2011, 08:30 AM
Hello M,

Thank you for this question. There is an example in our demo application which demonstrates the usage of IDataError interface. It is located under: GridView >> Manipulate data >> Indicate Errors

The DataError event is not recommended to use when validating cell values. In this case you can handle CellValidating or RowValidating events. Please consider the GridView >> Manipulate data >> Validate Changes example in our demo application.

You can find more information regarding the data validation in RadGridView in our online help.

If you have further questions, do not hesitate to contact us.
 
Regards,
Jack
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>
Tags
GridView
Asked by
m
Top achievements
Rank 1
Answers by
Jack
Telerik team
Share this question
or