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

CurrentCellValidating event

Hi, Im my application the currentcellvalidating event is being called twice once i try to move out of a cell. I am not able to figure out why. private void m_SlbGridDSC_CurrentCellValidating(object sender, System.ComponentModel.CancelEventArgs e) { m_CurrentCol = m_SlbGridDSC.CurrentCellInfo.ColIndex; m_CurrentRow = m_SlbGridDSC.CurrentCellInfo.RowIndex; float val; if (m_CurrentRow > 0 && ( m_CurrentCol >=m_LengthIndex - 1 && m_CurrentCol <= m_LinearWeightIndex - 1 ) && 0 != m_SlbGridDSC.CurrentCell.Renderer.ControlText.ToString().Length ) { m_Saved = false; prevVal = m_SlbGridDSC[m_CurrentRow,m_CurrentCol].Text; try { val = float.Parse(m_SlbGridDSC.CurrentCell.Renderer.ControlText.ToString() ); if( val <= 0 ) { DisableControls(); m_LblMessage.ImageIndex = 0; m_LblMessage.Text = ERR_POSITIVE_VAL; m_ButtonOK.Visible = true; m_ButtonOK.Enabled = true; } else { if ( m_ODIndex - 1 == m_CurrentCol ) { if ( m_SlbGridDSC[m_CurrentRow,m_IDIndex - 1].Text.Length > 0 ) { if( val <= float.Parse(m_SlbGridDSC[m_CurrentRow,m_IDIndex - 1].Text)) { DisableControls(); m_LblMessage.ImageIndex = 0; m_LblMessage.Text = ERR_OD_GREATERTHAN_OD; m_ButtonOK.Visible = true; m_ButtonOK.Enabled = true; } } } else if ( m_CurrentCol == m_IDIndex - 1 ) { if ( m_SlbGridDSC[m_CurrentRow,m_ODIndex - 1].Text.Length > 0 ) { if( val >= float.Parse(m_SlbGridDSC[m_CurrentRow,m_ODIndex - 1].Text)) { DisableControls(); m_LblMessage.ImageIndex = 0; m_LblMessage.Text = ERR_ID_LESSTHAN_OD; m_ButtonOK.Visible = true; m_ButtonOK.Enabled = true; } } } } } catch( FormatException ) { m_LblMessage.ImageIndex = 0; m_LblMessage.Text = ERR_NUMERIC_VAL; DisableControls(); m_ButtonOK.Visible = true; m_ButtonOK.Enabled = true; } } } This is how i am handling the CurrentCellValidating function. Can you help?

3 Replies

AD Administrator Syncfusion Team December 29, 2004 09:49 AM UTC

CurrentCellValidating is normally hit only once. Are you subscribing to this event twice (somehow - say in VB you have both a Handles clause and a AddHandler statement??)? You can put a stop at the top of your CurrentCellValidating code, and then examine both call stacks when this stop is being hit twice. That may shed some light on what is triggering the double call. I am not sure what you DisableControls call does, but this might trigger a second validate call. Checking callstack would pick this out. (Stepping through the code in your CurrentCellValidating handler would also pick this up if you leave the stop at the while you step. If you own our source code and use our Assembly Manager to build and set up for use, debug versions of our libraries, then th call stack would include our library code as well.

AD Administrator Syncfusion Team December 31, 2004 07:57 AM UTC

I can find out the cause of the problem. The CurrentCellValidatingEvent is being fired twice because i am setting the Enabled property of GridControl to false in the Disablecontrols functions. My requirement is if the user does not enter a valid message then i need to display an error message in a message area which i have created. The message area has a OK button . So until the user clicks on OK button the grid cannot get focus. Imagine a case when you show messages using MessageBox.Show method. But i cannot use pop up windows showing error messages. I have to display the error message in the message area. Can you please tell how can i overcome this problem?

AD Administrator Syncfusion Team December 31, 2004 09:15 AM UTC

Can you set a flag before you disable the grid?Then in CurrentCellValidating, test this flag and do not do your validation code if it is set. This way your code would only be hit once. Will this solve your problem?

Live Chat Icon For mobile
Up arrow icon