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

handle exception raised by bound IEditableObject.EndEdit

2 Answers 35 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Andrea
Top achievements
Rank 1
Andrea asked on 02 Jul 2014, 12:44 PM
Hello, can I catch the exception raised by a databounditem (that implements ieditableobject and idataerrorinfo) ?

At the moment after the user edit a row and insert invalid values IEditableObject.EndEdit throw an exception and the program terminate.

I also tried to add a Validating event handler but looks like the IEditableObject.EndEdit is called before the Validating event.

Also tried to handle the DataError event but with no success.

Best regards.
Andrea

2 Answers, 1 is accepted

Sort by
0
Andrea
Top achievements
Rank 1
answered on 03 Jul 2014, 01:02 PM
Looks like RowValidating and Validating events are not called when an editor is opened and you quit editor by clicking inside the grid but outside the area covered by data columns as per attached image.

Luckily I can ask who write EndEdit method to optionally trap all the exceptions found while EndEdit is running, but imho the grid should be able to catch the EndEdit exceptions and notify the owner of an exception using (maybe) an event.

0
Peter
Telerik team
answered on 07 Jul 2014, 10:43 AM
Hello Andrea,

Thank you for writing.

I would like to start with the clarification that the logic in our grid that is related to IEditableObject interface is executed between the RowsChangind and RowsChanged events and not on CellEndEdit, because one row usually represents one business object. Therefore, you can handle the RowsChanging event and execute your validation logic.
 
If this approach is not suitable for your scenario as an alternative you can subscribe for Grid's CellValueChanged event in order to handle the exception in your business object. For example:
private void CellValueChanged(object sender, GridViewCellEventArgs e)
{
    IEditableObject editbaleObject = e.Row.DataBoundItem as IEditableObject;
    if (editbaleObject != null)
    {
        try
        {
          editbaleObject.EndEdit();
          int num = this.ProductPriceTableAdapter.Update(this.HolidayDinnersDataSet);
          this.HolidayDinnersDataSet.AcceptChanges();//update the object inside
        }
        catch      
        {
               MessageBox.Show("Please, Enter a Valid value:); 
        }
    }  
}

I hope that this will be applicable for your scenario. Let me know if you have any additional questions.

Regards,
Peter
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
GridView
Asked by
Andrea
Top achievements
Rank 1
Answers by
Andrea
Top achievements
Rank 1
Peter
Telerik team
Share this question
or