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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Resetting a field''s value if validation fails

Thread ID:





39792 Jan 18,2006 12:16 PM UTC Jan 19,2006 08:26 PM UTC WinForms 3
Tags: GridControl
Nick Dalgiannakis
Asked On January 18, 2006 12:16 PM UTC

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

Administrator [Syncfusion]
Replied On 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. 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.


Nick Dalgiannakis
Replied On 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

stanleyj [Syncfusion]
Replied On 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


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.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon 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.Close Icon