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

CellErrorMessage

Can you help me. How can I change the displayed error message for an cell. For example I have column type of byte, when I enter some string, for example "dfg" I will see that cell becomes red and error message like "dgf is not a valid value for Byte" How can I change displayed error message for cell, or to which event I must subscribe to disable this.

6 Replies

AD Administrator Syncfusion Team March 7, 2007 03:57 PM UTC

Hi Alexander,

You can subscribe the 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. Here is a code snippet.

//hook the event
gridGroupingControl1.TableControlCurrentCellErrorMessage += new GridTableControlCurrentCellErrorMessageEventHandler(gridGroupingControl1_TableControlCurrentCellErrorMessage);

void gridGroupingControl1_TableControlCurrentCellErrorMessage(object sender, GridTableControlCurrentCellErrorMessageEventArgs e)
{
MessageBox.Show("Your Text Here");
e.Inner.Cancel = true;
}

Best Regards,
Haneef


AS Aleksander Sadovnikov March 9, 2007 07:54 AM UTC

Thnx, but I need to change not an message box, but error message that is displayed in cell.

Thank you for reply.

>Hi Alexander,

You can subscribe the 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. Here is a code snippet.

//hook the event
gridGroupingControl1.TableControlCurrentCellErrorMessage += new GridTableControlCurrentCellErrorMessageEventHandler(gridGroupingControl1_TableControlCurrentCellErrorMessage);

void gridGroupingControl1_TableControlCurrentCellErrorMessage(object sender, GridTableControlCurrentCellErrorMessageEventArgs e)
{
MessageBox.Show("Your Text Here");
e.Inner.Cancel = true;
}

Best Regards,
Haneef


AD Administrator Syncfusion Team March 9, 2007 05:48 PM UTC

Hi Alexander,

You catch TableControlCurrentCellErrorMessage event and set e.TableControl.CurrentCell.ErrorMessage to be the string you want displayed. Please try the suggestion and let me know if this.

private void gridGroupingControl1_TableControlCurrentCellErrorMessage(object sender, GridTableControlCurrentCellErrorMessageEventArgs e)
{
e.TableControl.CurrentCell.ErrorMessage = "welcome";
}

Best regards,
Haneef


AD Administrator Syncfusion Team March 12, 2007 03:17 PM UTC

Thnx. But it not working.
I try this
private void gridGroupingControl1_TableControlCurrentCellErrorMessage(object sender, GridTableControlCurrentCellErrorMessageEventArgs e)
{
GridColumnDescriptor columDesc = e.TableControl.Table.GetColumnDescriptorAt(e.TableControl.CurrentCell.RowIndex, e.TableControl.CurrentCell.ColIndex);

if (columDesc == null)
{
e.Inner.Cancel = false;
return;
}

string columnName = null;
if (columDesc != null)
{
columnName = columDesc.Name;
}

DataColumn col = _localDataTable.Columns[columnName];

string errMessage = GetCellErrorMessage(e.TableControl.CurrentCell, col.GetType());
if (errMessage.Length > 0)
{
//e.Inner.Cancel = true;
e.TableControl.CurrentCell.ErrorMessage = errMessage;
e.TableControl.CurrentCell.Exception = new Exception(errMessage);
//MessageBox.Show(errMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
e.Inner.Cancel = false;
}

But error message is not that i`m trying to set. It still the same. Can you help me with this.


>Hi Alexander,

You catch TableControlCurrentCellErrorMessage event and set e.TableControl.CurrentCell.ErrorMessage to be the string you want displayed. Please try the suggestion and let me know if this.

private void gridGroupingControl1_TableControlCurrentCellErrorMessage(object sender, GridTableControlCurrentCellErrorMessageEventArgs e)
{
e.TableControl.CurrentCell.ErrorMessage = "welcome";
}

Best regards,
Haneef


RT Rocky Tatlay May 4, 2007 05:36 PM UTC

Hello,

I looked at the examples and decided to use the GridDrawCellEventHandler. It works well except for some unexpected results. I’m using a grouping grid control and the errors icons will not draw on the header rows when the records are not expanded. Once expanded, the error icons draw on the parent records only once you enter the child records. They will disappear if you collapse the group. The child records errors draw perfectly but the parent error icons appear and disappear unexpectedly. I’m using separate event handlers for the parent and child tables.

groupinggridcntrl.GetTableControl("parenttable").DrawCell +=new GridDrawCellEventHandler(groupinggridcntrl_DrawParentErrors);

groupinggridcntrl.GetTableControl("childtable").DrawCell +=new GridDrawCellEventHandler(groupinggridcntrl_DrawChildErrors);

Any ideas how to get the parent rows to draw errors when they should?

Here’s a code snippet of the event:

void groupinggridcntrl_DrawParentErrors(object sender, GridDrawCellEventArgs e)
{
GridTableControl tc = sender as GridTableControl;
GridTableCellStyleInfo style = tc.GetTableViewStyleInfo(e.RowIndex, e.ColIndex) as GridTableCellStyleInfo;
Record r = style.TableCellIdentity.DisplayElement.GetRecord();

if (style != null
&& style.TableCellIdentity.Column != null
&& r != null)
{
col = style.TableCellIdentity.Column.Name;

//code for determinig if error should occur on cells

hashKey = hash_HdrID + hash_DtlID + col;

if (errHash.ContainsKey(hashKey))
{
e.Renderer.Draw(e.Graphics, e.Bounds, e.RowIndex, e.ColIndex, e.Style);
Icon failureIcon = SystemIcons.Error;

Rectangle iRect = new Rectangle(new Point(e.Bounds.Right - 20, e.Bounds.Top), new Size(20, e.Bounds.Height));
e.Graphics.DrawIcon(failureIcon, iRect);
e.Cancel = true;
}
}
}


RA Rajagopal Syncfusion Team May 8, 2007 09:53 PM UTC

Hi Rocko,

For displaying custom error messages in grid handling the TableControlCurrentCellValidating/TableControlCurrentCellErrorMessage events should be fine. Please try the below sample that works in showing custom error message properly.

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

Let us know if this helps.
Regards,
Rajagopal

Loader.
Live Chat Icon For mobile
Up arrow icon