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.
Unfortunately, activation email could not send to your email. Please try again.

Intercepting errors in GGC

Thread ID:

Created:

Updated:

Platform:

Replies:

78518 Dec 16,2008 12:40 PM Dec 20,2008 07:52 AM Windows Forms 5
loading
Tags: GridControl
Peter Trevor NO LONGER WITH COMPANY
Asked On December 16, 2008 12:40 PM

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?



Rajadurai C [Syncfusion]
Replied On December 17, 2008 09:01 AM

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


Peter Trevor NO LONGER WITH COMPANY
Replied On December 17, 2008 12:35 PM

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.)



Rajadurai C [Syncfusion]
Replied On December 18, 2008 12:26 AM

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


Administrator [Syncfusion]
Replied On December 18, 2008 09:16 AM

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




Rajadurai C [Syncfusion]
Replied On December 20, 2008 07:52 AM

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


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;