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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

CurrentCellValidating

Thread ID:

Created:

Updated:

Platform:

Replies:

40086 Jan 24,2006 10:17 PM UTC Mar 10,2006 06:35 PM UTC Windows Forms 5
loading
Tags: GridControl
Mike Nohr
Asked On January 24, 2006 10:17 PM UTC

I''m using the currentcellvalidating event to perform some date and text validation. In the case when the validation fails I display an error dialog box then set e.Cancel = true; This appears to throw off the validation focus event model somewhat as focus is returned to the grid it now fires an enter event and finally another currentcellvalidating event again. Is there anyway to have currentcellvalidating to return focus to the invalid cell without firing any additional events? Thx Mike

Administrator [Syncfusion]
Replied On January 25, 2006 09:42 AM UTC

Hi Mike, To validate the CurrentCell, you need to handle the CurrentCell Validating/ Validated/ ValidateFailed EventHandler. Here  is the code snippet in the CurrentCellValidating Event. GridCurrentCell cc  =  this.gridDataBoundGrid1.CurrentCell;            if(cc.ColIndex == 2) {             string newValue = cc.Renderer.ControlText;             try             {                     double d = double.Parse(newValue);            }             catch            {                       cc.ErrorMessage = "Enter InValid";                     e.Cancel = true;                                     } } Refer to the sample for details. Here is KB Link for more detail : What are the different validation events and event members? When are they triggered and how are they used?  Let me know if you need any further assistance.   Regards, Madhan.

Forum_25Jan_40086.zip

Mike Nohr
Replied On February 9, 2006 01:07 AM UTC

I am using the CurrentCellValidating method as you described above. The problem occurs in this scenario: 1. Click in the cell so that there is a carrot in it 2. Cell contains invalid data 3. Click focus to another windows form not containing the grid that is validating. 4. CurrentCellValidating runs and fails. I set e.Cancel = true; and pop up an error dialog box. 5. The focus is then returned to the control firing a grid on enter event. 6. I believe next thing that happens is the grid sets focus to the cell that had the error then puts the cursor in that cell. This seems to force another currentcellvalidating event to fire on the cell. 7. Of course CurrentCellValidating fails again and I get another error dialog box. My question is is there anyway to supress all additional events from being fired when the grid returns focus to the cell that is invalid? I''ve tested this scenario with having the event fire by clicking on another cell in the grid and validate only gets called once. Also if I only have focus on the cell with the invalid data but no cursor in it then it too only fires validation once. Below is a sample of the code: private void gdgMessages_CurrentCellValidating(object sender, System.ComponentModel.CancelEventArgs e) { if(!validateCurrentCellPO()) { e.Cancel = true; // Display error dialog ErrorDialog ed = new ErrorDialog("Input Error", getMessage(ERR_MM_MSG_TEXT), ""); ed.ShowDialog(); } } Thanks!

Administrator [Syncfusion]
Replied On February 10, 2006 02:09 PM UTC

Hi Mike, You can avoid this problem by overriding the forms WndProc and handling the Form''s Activated/Deactived Events. Here is the code snippet public const int SC_CLOSE = 0xF060; public const int WM_SYSCOMMAND = 0x0112; protected override void WndProc(ref System.Windows.Forms.Message m) { if(m.Msg == WM_SYSCOMMAND && (int)m.WParam == SC_CLOSE) { this.flag = false; this.Close(); } base.WndProc(ref m); } Here is a sample Let me know if this does not help. Can you post a small sample showing this problem or tell us how to see it in the Browser sample/Attached sample Regards, Madhan

Mike Nohr
Replied On March 10, 2006 04:24 PM UTC

I''ve tried the work around solution that you proposed but validating still gets called twice. Activate and Deactivate don''t get called at all during the validation process. Is there another work around you might be able to suggest?

Mike Nohr
Replied On March 10, 2006 06:35 PM UTC

I''ve mapped out the sequence of events for the three scenarios: Clicking on a different cell in the same grid: CurrentCellActivated CurrentCellDeactivating CurrentCellValidated Row Leave CurrentCellControlLostFocus CurrentCellControlGotFocus CurrentCellDeactivateFailed ValidateFailed Clicking on a control in the same C# Form: CurrentCellControlLostFocus Leave Validating CurrentCellValidating CurrentCellValidated RowLeave ValidateFailed Enter CurrentCellControlGotFocus Clicking on another visible form that doesn''t contain the grid: CurrentCellControlLostFocus Leave Validating CurrentCellValidating CurrentCellValidated Row Leave ValidateFailed Enter Validating CurrentCellvalidating CurrentCellValidated Row Leave CurrentCellGotFocus ValidateFailed Enter CurrentCellControlLostFocus CurrentCellGotFocus It''s clear there is a bug in how the grid behaves in the last scenario. If I supress the validating from executing then the carrot is never put in the cell. It appears that the 2nd set of validation is performed when the cell with focus puts the carrot in the control in the cell. Is there a way I can avoid this. I''ve been looking for a work around and as of yet i''ve been unable to find one.

CONFIRMATION

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.

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

;