Home Forums WinForms controls Xceed Grid for WinForms Catching exception from datatable…

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #16353 |

    We have an Xceed grid bound to a datatable with business and validation logic residing within the datatable class. When field validation fails or business rules are violated an exception is thrown.

    For example we subscribe to the ColumnChanging event within the datatable class:

    ColumnChanging += ColumnChanging;

        public void ColumnChanging(object sender, DataColumnChangeEventArgs e)
        {
            if (e.Column.Equals(this.StockPriceColumn)) {
                if (!Convert.IsDBNull(e.ProposedValue) && (decimal)e.ProposedValue < 0) {
                    throw new ArgumentException(“StockPrice cannot be less than zero”, “StockPrice”);
                }
            }
     

    Since the DataRows in the grid are bound to the datatable the EndEdit appears to happen automatically when the user navigates away from the cell (I may be wrong) so I have no way of wrapping it in a Try Catch block to catch the underlying exceptions thrown in the datatable?

    Note: The code still works however the Xceed.Grid.dll throws 3 first chance exceptions of type ‘Xceed.Grid.GridValidationException’

    Any help would be appreciated.

    Imported from legacy forums. Posted by janon (had 848 views)

    User (Old forums)
    Member
    Post count: 23064

    Do you only get these exceptions when in debug mode, and with the debugger set to break on all exceptions?  If so, you can ignore them, they will go unnoticed at runtime in release mode, and the value in the cell should revert back to the previous value when the user navigates away from it.

    You can also handle the ValidationError event, in which you will be able to intervene, e.g. keep the cell in edit mode, so the user must change the value or press “ESC” to be able leave the cell.

     

    Imported from legacy forums. Posted by André (had 249 views)

    User (Old forums)
    Member
    Post count: 23064

    Yes, it only happens when in debug mode with debugger set to break on all exceptions. We have subscribed to the ValidationError event of both the datarow and datacell, as you described, and issue a ‘e.CancelEdits = False;’ to prevent the user from navigating from the cell when errors exists, it works brilliantly.

    We were concerned with the debugger exceptions during development but will ignore them as you recommend since they have no noticeably ramifications on the applicatoin.

    Thank you for your quick response!

    Imported from legacy forums. Posted by janon (had 767 views)

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.