We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Intercepting errors in GGC

Hi

I have bound a table in a dataset to a GGC grid. The table has a multi-column primary key defined. If I enter a duplicate row and then attept to leave the table row an error message is produced. So far so good, except I want to intercept that error message and replace it with something more user friendly. How do I do this in C# 2.0?



5 Replies

RC Rajadurai C Syncfusion Team December 17, 2008 02:01 PM UTC

Hi Pedro,

Thanks for your interest in Syncfusion products.

To suppress the message thrown and provide your own message, please try handling TableControlCurrentCellValidating event.

e.Inner.Cancel = true;
e.TableControl.CurrentCell.ErrorMessage = "ColumnID must be unique";
e.TableControl.CurrentCell.Exception = new Exception(e.TableControl .CurrentCell .ErrorMessage );
cc.MoveTo(e.TableControl.CurrentCell.RowIndex, e.TableControl.CurrentCell.ColIndex, GridSetCurrentCellOptions.SetFocus);


In the codesnippet shown above, Cancel property is set to true inorder to suppress the usual message thrown.

Regards,
Rajadurai



PT Peter Trevor NO LONGER WITH COMPANY December 17, 2008 05:35 PM UTC

Thanks Rajadurai, but in that event handler how do I detect that I have that error in the first place? (The "SaveRecord" error doesn't appear to be a cell error.)




RC Rajadurai C Syncfusion Team December 18, 2008 05:26 AM UTC

Hi Pedro,

Thanks for your update.

Even if you set custom messages to be thrown in CurrentCellValidating event, when you move from the current record, the "SaveRecord" error message will be first to be thrown followed by other. Because, you are setting the dataset to have unique values in columnid. On leaving a record after editing, the grid will get refreshed. At this time, the grid tries to save data in grid to dataset binded to it. Here validation take place and the exception message will be thrown if the value is invalid.

To supress this message you can follow the code snippet in CurrentCellValidating event provided in last update.

Please let me know if you have any further concerns.

Regards,
Rajadurai



AD Administrator Syncfusion Team December 18, 2008 02:16 PM UTC

Rajadurai,

Validating in this manner, moves the validation of the business object from the model to the grid, and the reason why I would use the bound grid is to keep a clean separation between the grid and the business object.


I was following another thread where it was suggested that the business object throw an exception when it is being set, if the rules are being violoated, but if the Business object has many attributes [ which is most common] then the exception mechanism does not seem right. [ Since the grid will persist to the backing store one cell at a time, this will only report an error on the first violated attribute]

Is there a way to turn on validation by implementing IDataErrorInfo interface? The Microsoft grid does this.

Any help in explaining the correct way to handle business errors on bound grids would be highly appreciated

-A

>Hi Pedro,

Thanks for your update.

Even if you set custom messages to be thrown in CurrentCellValidating event, when you move from the current record, the "SaveRecord" error message will be first to be thrown followed by other. Because, you are setting the dataset to have unique values in columnid. On leaving a record after editing, the grid will get refreshed. At this time, the grid tries to save data in grid to dataset binded to it. Here validation take place and the exception message will be thrown if the value is invalid.

To supress this message you can follow the code snippet in CurrentCellValidating event provided in last update.

Please let me know if you have any further concerns.

Regards,
Rajadurai





RC Rajadurai C Syncfusion Team December 20, 2008 12:52 PM UTC

Hi Amjad,

Thanks for your interest in Syncfusion products.

Please refer to the forum thread below as it illustrates handling the business objects in case of exception and use of custom errormessage.
http://www.syncfusion.com/support/forums/message.aspx?MessageID=55049

Please let me know with more details if it doesn't serve your needs.

Regards,
Rajadurai


Loader.
Live Chat Icon For mobile
Up arrow icon