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

ErrorProvider - Exception and GGC

Hi,

we have a GGC which is bound to a business object via complex databinding. Now we handle the validation of each value in the business object. If the validation fails (e.g. the value is not in a defined range) we throw an exception.

Now if we throw an exception the grid shows an error provider in the specific cell and a messagebox with the exception message we defined. How can we influence this behavior. The default errorprovider is nice but we don't want to show the message box. How can we disable the messagebox. I have attached a sample where you can see what I mean. If you change a cell value in first column you get the described behavior.

Any help would be great

ErrorExample.zip

15 Replies

AD Administrator Syncfusion Team January 23, 2007 03:41 PM UTC

Hi Tom,

In the Essential Studio 4.2, We have newly added a TableControlCurrentCellErrorMessage event which you can handle and display your own custom message box whenever the grids CurrentCell.DisplayWarningText (as a result of some kind of validation error) is called. Please refer to the attached sample for implementation.

Modified sample : ErrorExample.zip

void gridGroupingControl1_TableControlCurrentCellErrorMessage(object sender, GridTableControlCurrentCellErrorMessageEventArgs e)
{
e.Inner.Cancel = true;
}

Best Regards,
Haneef


AD Administrator Syncfusion Team January 23, 2007 03:58 PM UTC

Hi Haneef,

thanks for your sample, but now when I change a value in the "Data" column I can't see the default error provider.

(In the setter of the business object I have always thrown an exception if the value is changing just for debugging - and this exception isn't shown anymore) When I enter a string then I get the desired behavior - i just see the error provider with a message like "dskjdl is not a valid value for Int32).

How can I get this error provider for my exception? You can see the described behavior in the example you have uploaded.

Thanks in advance


AD Administrator Syncfusion Team January 23, 2007 05:00 PM UTC

Hi ,

Please try this code snippet.

void gridGroupingControl1_TableControlCurrentCellErrorMessage(object sender, GridTableControlCurrentCellErrorMessageEventArgs e)
{
if (e.Inner.Text == "Value is not valid - how can I handle this here")
e.Inner.Cancel = true;
}

Best Regards,
Haneef


AD Administrator Syncfusion Team January 24, 2007 09:02 AM UTC

Hi Haneef,

this doesn't work. I have attached the modified sample where you can see what I mean. I have added condition checks in the setter of my business object. Now if you enter a negative value for the data column you should get an error provider an no messagebox, but nothing happens. Can you take a look what's wrong with the code?

Cheers

ErrorExampleModified.zip


AD Administrator Syncfusion Team January 25, 2007 07:08 AM UTC

Hi,

just wanna bring this thread up - are there any news about that?

Thanks in advance


AD Administrator Syncfusion Team January 25, 2007 08:54 PM UTC

Hi,

You can handle the TableControlCellDrawn to draw the error icon in a invalid cell without error messagebox popup. Here is a sample code snippet to show the error icon in a cell.

void gridGroupingControl1_TableControlDrawCell(object sender, GridTableControlDrawCellEventArgs e)
{
GridCurrentCell cc = e.TableControl.CurrentCell;
GridTableCellStyleInfo style = e.Inner.Style as GridTableCellStyleInfo;

if (ErrorCell != null && ErrorCell.RowIndex == e.Inner.RowIndex
&& ErrorCell.ColIndex == e.Inner.ColIndex )
{
// Highlight error cell
Brush br = new SolidBrush(Color.FromArgb(64, Color.Red));
e.Inner.Graphics.FillRectangle(br, e.Inner.Bounds);
br.Dispose();
try
{
e.Inner.Cancel = true;
Rectangle iconBounds = Rectangle.FromLTRB(e.Inner.Bounds.Right - 15, e.Inner.Bounds.Top, e.Inner.Bounds.Right, e.Inner.Bounds.Bottom);
iconBounds.Offset(-2, 0);
IconPainter.PaintIcon(e.Inner.Graphics, iconBounds, Point.Empty, "SFERROR.BMP", Color.Red);

}
catch
{
}
}
}

Please refer to the attached sample for implementation.
NewErrorExample.zip

Best Regards,
Haneef


AD Administrator Syncfusion Team January 26, 2007 08:09 AM UTC

Hi Haneef,

first of all I have to say thank you for your effort. But I am not really happy with this approach. I like the standard behavior of the grid (the errorprovider in the cell and so on). But I just want to show my own error message when I hover over the error icon but I don't want to see the message box. Is there no easy way to handle this?


AD Administrator Syncfusion Team January 26, 2007 08:56 AM UTC

Hi Haneef,

Furthermore I forgot to ask some more question about your approach. Why do I need the following event:

void gridGroupingControl1_RecordValueChanging(object sender, Syncfusion.Grouping.RecordValueChangingEventArgs e)
{
if (e.Column == "Data")
e.Record.EndEdit();
}

When I disable this event - your example doesn't work anymore.


Another question is: When you enter a string literal in a cell like e.g. "adjk" - you get another error behavior than when you enter a negative value (which is my own error). How can I make both error types looking the same?

Thanks in advance for your help


AD Administrator Syncfusion Team January 29, 2007 03:18 PM UTC

Just wanna know - any news about that?


AD Administrator Syncfusion Team January 29, 2007 09:56 PM UTC

Hi Tom,

I regret for the inconvenience caused.

If you want to show the own error message when mouse overing the error icon without default message box in a grid then you should handle the ExceptionRaised event for handling the unknown exception(It has been raised while modifying the underlying data in datasource) and TableControlCurrentCellErrorMessage event for handling the known exception in a cell. Here is a code snippet to show this.

private void SetErrorText(object sender, string ErrorMsg)
{
GridGroupingControl grid = sender as GridGroupingControl;
foreach (CurrentRecordProperty prop in grid.Table.CurrentRecordManager.Properties)
{
if (prop.IsError)
prop.Exception = new Exception(ErrorMsg, prop.Exception.InnerException);
}
}

void gridGroupingControl1_ExceptionRaised(object sender, ExceptionRaisedEventArgs e)
{
//If you want to set default error message then call the SetErrorText(sender, e.Inner.Text);
SetErrorText(sender, "Your Text Message Here....");
e.Cancel = true;
}
void gridGroupingControl1_TableControlCurrentCellErrorMessage(object sender, GridTableControlCurrentCellErrorMessageEventArgs e)
{
e.Inner.Cancel = true;
//If you want to set default error message then call the SetErrorText(sender, e.Exception.Message);
SetErrorText(sender, "Your Text Message Here....");
}

Please refer to the attached sample for implementation.
ModifiedNewErrorExample.zip

Let me know if you are looking something different.
Best Regards,
Haneef


AD Administrator Syncfusion Team January 30, 2007 07:33 AM UTC

Hi Haneef,

this is almost what I was looking for. The only problem now is that I am not able to localize the tooltip text.

When I throw an exception while I am validating the cell value in my business object, the exceptionraised event is called, and there I can set the localized Exception.Message string.

But when you enter a string literal in a cell - only the currentcellerrormessage event is called and not the exceptionraised one. It seems even the setter of my business object is never called in this case - is there an automaticc type validation inside syncfusion? How can I handle the type validation in my setter so that even when I enter a string literal the validation is handled by my business object (with the excpetionraised event called)?

I am not sure if you understand my problem it's a little bit difficult to describe.

Thank you very much for your help so far - I hope you can give me a hint on that last issue.

Your support is great!


AD Administrator Syncfusion Team January 31, 2007 07:29 PM UTC

Just wanna bring this thread up - so that I can finish that part of my project.

Any help would be great.


AD Administrator Syncfusion Team January 31, 2007 08:06 PM UTC

Hi Tom,

Grid Storing Tech:

Normally, the grid will cache changes to a single row, and when you leave the row, it will push these changes to the underlying datasource. If you want to push the changes to the underlying datasource without leaving a row, then you can call Table.EndEdit. (You also may want to call CurrentCell.EndEdit before calling Table.EndEdit so that any pending changes to the current cell also get saved.)

The ExceptionRaised event is fired when a unknown exception has been cached while modifying underlying data in a datasource. But the TableControlCurrentCellErrorMessage event is fired when a unknow exception has been cached while modifying the internal cache in a grid.

If you want to show the localized tooltip on error cell, you need to set the CurrentRecordProperty.Exception property to new localized exception. The attached sample shows the "Your Text Message Here...." tooltip on error cell. Here is a code snippet.

//Use this method in ExceptionRaised event and CurrentCellErrorMessage event.
private void SetErrorCellTooltipText(object sender, string ErrorMsg)
{
GridGroupingControl grid = sender as GridGroupingControl;
foreach (CurrentRecordProperty prop in grid.Table.CurrentRecordManager.Properties)
{
if (prop.IsError)
prop.Exception = new Exception(ErrorMsg, prop.Exception.InnerException);
}
}

Please refer to the attached sample for implementation.
ModifiedNewErrorExample.zip

Let me know if i am missing something.

Best Regards,
Haneef


SK Sameer Khan December 18, 2008 06:24 PM UTC

What happens when more than one property of the model is in error?






NA Nisha Arockiya A Syncfusion Team December 19, 2008 01:01 PM UTC


Hi Sameer,

Thanks for your interest in Syncfusion Products.

Basically, CurrentRecordManager.Properties Property gets the collection of CurrentRecordProperty elements that contain modified values of the current record.

A CurrentRecordProperty element provides storage for modified values for the current Record in a CurrentRecordManager. CurrentRecordProperty objects are accessed through the collection returned by the Properties property of a CurrentRecordManager object.

Could you please let me know if i am missing anything??

Regards,
Nisha





Loader.
Live Chat Icon For mobile
Up arrow icon