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 and changing GridGroupingControl constraint error messages

Hi,

What is the proper method of intercepting the DataSet contstraint error message popups in the GridGroupingControl?

I have put together an example project that builds on my Widget Grouping example. For this example, I have set the "Name" column of the Widget table to be Unique and to not allow DBNull. The "WidgetTypeID" column in the same table also does not allow DBNull.

So, if I want to enter a new record and give it a Widget Name of "Bulldozer" it presents a popup message that says: "SaveRecord: Column ''Name'' is constrained to be unique. Value ''Bulldozer'' is already present." I want to change the message, header, and MessageBoxIcon of the MessageBox that is presented. I also want to change the MessageBox for the WidgetTypeID in a similiar manner.

How do I do this?

Please let me know if you require any additional explanation.

Thanks,
Scott


ErrorMessageGroupingGridExample_problem.zip

4 Replies

AD Administrator Syncfusion Team July 26, 2006 06:57 AM UTC

Hi Scott,

In the Essential Studio 4.2, We have newly added a CurrentCellErrorMessage 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. Here is a code snippet

private void WidgetGroupingGrid_TableControlCurrentCellErrorMessage(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableControlCurrentCellErrorMessageEventArgs e)
{
//To get the orginal error from e.Inner.Text
MessageBox.Show("AddNewUnique Error",MessageBoxButtons.OKCancel,MessageBoxIcon.Error );
e.Inner.Cancel = true;
}

private void WidgetGroupingGrid_TableControlCurrentCellValidating(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableControlCancelEventArgs e)
{
GridTableCellStyleInfo style = e.TableControl.CurrentCell.Renderer.CurrentStyle as GridTableCellStyleInfo;
if(style.TableCellIdentity.Column != null && style.TableCellIdentity.Column.Name == "Name")
{
if( e.TableControl.Table.CurrentRecord.Kind != DisplayElementKind.AddNewRecord)
{
e.TableControl.Table.CurrentRecord.EndEdit();
}
else
{
object Newobj = e.TableControl.CurrentCell.Renderer.ControlValue;
foreach( Record rec in e.TableControl.Table.Records)
{
if(Newobj.Equals(rec.GetValue(style.TableCellIdentity.Column.Name)))
{
MessageBox.Show("AddNewUnique Error","ErrorMessage",MessageBoxButtons.OKCancel,MessageBoxIcon.Error );
e.Inner.Cancel = true;
break;
}
}
}
}
}

Here is a modified sample.
http://www.syncfusion.com/Support/user/uploads/ErrorMessageGroupingGridExample_problem_39c55d11.zip

Let me know if you face any issues when implementing the above.
Best Regards,
Haneef


SM Scott Mercer July 26, 2006 03:56 PM UTC

Hi Haneef,

This is a step in the right direction, but it actually removes some of the default behavior that I wish to keep. Somehow the logic that we are implementing in the TableControlCurrentCellValidating event handler is prohibiting the exclamation from displaying around the grid cell. The validator exclamation mark is a great feature because it lets the user know exactly where the correction must be made.

What do we need to do to get the exclamation mark in the cell to re-appear?

Thanks,
Scott


SM Scott Mercer July 26, 2006 04:05 PM UTC

I also found something else. For some reason the TableControlCurrentCellValidating event is firing twice in the solution that you posted for me.

Obviously I could put some kind of class level field that tracks the state of the event and prevents it from firing twice, but I want to understand why it is doing this.

To make your example fire the event twice, follow these steps:
1) Begin adding a new Widget row by entering a unique value for the Widget Name and a Widget Type.
2) Go back and change the Widget name to "Bulldozer" so that it is the same as the first record. Hit the ENTER key. This should cause the event to pop up twice and show the error message twice.

Any ideas?

Thanks,
Scott


AD Administrator Syncfusion Team July 27, 2006 07:00 AM UTC

Hi Scott,

Issue 1: ErrorProvider on Invalid Cell.

You can handle the TableControlCellDrawn to draw the error icon in a invalid cell. Please find the code snippet below.

private void WidgetGroupingGrid_TableControlCellDrawn(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableControlDrawCellEventArgs e)
{
GridCurrentCell cc = e.TableControl.CurrentCell ;
if( cc.RowIndex == e.Inner.RowIndex && e.Inner.ColIndex == cc.ColIndex && IsInValid)
{
// Highlight error column
Brush br = new SolidBrush(Color.FromArgb(64, Color.Red));
e.Inner.Graphics.FillRectangle(br, e.Inner.Bounds);
br.Dispose();
try
{
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
{}
}
}
}

Here is a sample.
http://www.syncfusion.com/Support/user/uploads/ErrorMessageGroupingGridExample_problem_e2a97943.zip

Issue 2: TableControlCurrentCellValidating event fire twice.

Thanks for your update. I am afraid that i was not able to reproduce this issue here. If you could send us some more details on your issue, it will be helpful for us to debug and get it fixed at the earliest.

Thanks for your interest in Syncfusion products.
Best Regards,
Haneef

Loader.
Live Chat Icon For mobile
Up arrow icon