Resetting a field''s value if validation fails
Hi,
I''m using a DataBound grid and it seems that, by default, if there is a validation error (like typing a non-numeric string in a numeric cell), a message box with the relevant exception shows up. What''s the easiest way of overriding this behavior to simply reset the cell''s value to the last valid value and move on? Which event handlers do I need to implement?
I''ve tried binder.resetField(currentCell.colIndex) in the grid''s ValiateFailed event but that didn''t work.
Thanks for your help.
Rgds,
Nick
SIGN IN To post a reply.
3 Replies
AD
Administrator
Syncfusion Team
January 18, 2006 03:13 PM UTC
Hi Nick,
To handle, the validation error. You can handle it in the CurrentCellValidating Event. Here is the Code snippet.
Forum_18Jan_39792.zip
private void gridDataBoundGrid1_CurrentCellValidating(object sender, System.ComponentModel.CancelEventArgs e)
{
GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell;
int i = Convert.ToInt32(this.gridDataBoundGrid1[cc.RowIndex,cc.ColIndex].CellValue);
if(cc.ColIndex == 2)
{
string newValue = cc.Renderer.ControlText;
try
{
double d = double.Parse(newValue);
}
catch
{
e.Cancel = true;
cc.Renderer.ControlText = i.ToString();
}
}
}
Refer to sample for details
Let me know if you further assistance,
Regards,
Madhan.Forum_18Jan_39792.zip
ND
Nick Dalgiannakis
January 19, 2006 11:34 AM UTC
Thanks for your reply Madhan. This works well if you put your validation code on the grid level. I would like, however, to let each cell type (including custom types) deal with its own validation (so leave it to each model/renderer). However, I''m not sure which method I need to implement/override to get this done.
Is there any documentation that details what the chain of events is (and on what objects) when a user goes to a cell, types a value and then moves out of that cell, specifically for DataBound grids? And how do the default handlers behave (i.e. what methods do they call)?
Thanks again for your help.
Rgds,
Nick
ST
stanleyj
Syncfusion Team
January 19, 2006 08:26 PM UTC
Hi Nick,
If you browse through the CellTypes samples that are shipped, that will display an event log which, will show the order of the currentcell events that are raised and the values that are in the cell as the events occur. You will be able to see mouse events as well.
You can also learn through the knowledgeBase articles, here is one article explaining the different validation events.
Best regards,
Stanley
SIGN IN To post a reply.
- 3 Replies
- 3 Participants
-
ND Nick Dalgiannakis
- Jan 18, 2006 12:16 PM UTC
- Jan 19, 2006 08:26 PM UTC