handle exception raised by bound IEditableObject.EndEdit

3 posts, 0 answers
  1. Andrea
    Andrea avatar
    73 posts
    Member since:
    Oct 2012

    Posted 02 Jul 2014 Link to this post

    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.
  2. Andrea
    Andrea avatar
    73 posts
    Member since:
    Oct 2012

    Posted 03 Jul 2014 in reply to Andrea Link to this post

    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.

  3. Peter
    Peter avatar
    1148 posts

    Posted 07 Jul 2014 Link to this post

    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)
              int num = this.ProductPriceTableAdapter.Update(this.HolidayDinnersDataSet);
              this.HolidayDinnersDataSet.AcceptChanges();//update the object inside
                   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.

    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.
Back to Top