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

activatecurrentcellbehavior and CurrentCell.CancelEdit

We have been setting activatecurrentcellbehavior to a mix of clickoncell, selectall, and dblclickoncell. What ive noticed now over time is that the currentcell.canceledit doesnt work the same between those settings. if u have a currentcellvalidating event and some invalid data and try to do the currentcell.canceledit it may or may not work depending on the setting of the activatecurrenctcellbehavior. if its set to clickoncell or dblclickoncell the cancel edit will work and revert back to the data in the cell before the error. if the setting is set to select all it wont. now here is the scenario that causes it. if its set to select all and u enter in some invalid data and then click off the cell it will give u the error message from the cellvalidating even but wont revert back the data until u click again on another cell. if however u enter the same invalid data and then arrow off the cell and get the error message then it will revert the cell back to the valid data immediatly. this only seems to happen on the selectall setting. if u want a sample i can whip one up for you in visual studio 2003 in basic. Thanks Phil

7 Replies

AD Administrator Syncfusion Team May 27, 2004 06:56 PM UTC

The way CurrentCellValidating was designed to work is that you set e.Cancel = true (and that is all). The focus should remain on the same cell. There is normally no call to CurrentCell.CancelEdit. Have you tried just setting e,Cancel = true, and then letting the grid handle everything from that point? Is there some special reason you are calling CanceEdit?


PB Philip Bishop May 28, 2004 09:57 AM UTC

Ok i dont know if i made that to confusing or not. When there is an error the people writing our specs for this app want the cell to revert back to the value that was in the cell before the invalid data was entered. So when u say just use e.cancel = true that wont work. All that does is gives the error and FORCES them to fix it or hit escape to reset the value which again the people writing the specs dont like. They just want the value to be reset. Now unless i''m doing something wrong, e.cancel = true doesnt do anything other then make them fix the invalid data. I''ve attached a sample for you to show u what i''m talking about. I have 2 grids on the sample. The grid on the left has selectall set and the grid on the right has doubleclickoncell. Now i''ve commented out the canceledit like u said in the grid on the left. All it does is gives and error message and if u go in after the following and uncomment and run again thats all it still does unlike the grid on the right. Valid values for all cells in both grids are 501 - 532. So if u go to each grid in 1,1 and type in like 999 and then the key is to MOUSE OFF THE CELL(not arrow)u will see that on the cell on the left grid it will give the error and not reset or canceledit the data. if u do the same to 1,1 on the right grid u will get the error then notice by doing the canceledit the data reverts back to what was orginally in the cell before the invalid data was entered. Now again if u un comment the canceledit for the grid on the left u will notice they dont behave the same way. Maybe most people want them to fix it but the way we''ve been asked to do it is to put the value back so in case they dont want to change it now if they have made a mistake. Thanks Phil activecurrentcell_4063.zip


AD Administrator Syncfusion Team May 28, 2004 11:08 AM UTC

This code seems to make things behave the way you require them. It just resets the current cell text to what is stored in the grid cell, and then invaildates the cell to redraw it with the changed text, and cancels the validation. It does not try to call CurrentCell.CancelEdit. Dim i As Single i = CSng(Me.gridcontrol1.CurrentCell.Renderer.ControlText) errorcode = 0 Select Case i Case 0, 501.0F To 532.0F Case Else MessageBox.Show("Cell value must be between 501 and 532." & ControlChars.CrLf & _ "The invalid value will be reset.", _ "QUASAR: Invalid Value Entered", MessageBoxButtons.OK, _ MessageBoxIcon.Warning) Dim cc As Syncfusion.Windows.Forms.Grid.GridCurrentCell = Me.gridcontrol1.CurrentCell cc.Renderer.Control.Text = Me.gridcontrol1(cc.RowIndex, cc.ColIndex).Text Me.gridcontrol1.Invalidate(Me.gridcontrol1.ViewLayout.RangeInfoToRectangle(cc.RangeInfo, Syncfusion.Windows.Forms.Grid.GridCellSizeKind.ActualSize), True) e.Cancel = True End Select


AD Administrator Syncfusion Team May 28, 2004 11:09 AM UTC

Please ignore the errorcode = 0 in the code snippet. It was left over from some other tries at doing this.


PB Philip Bishop May 28, 2004 11:12 AM UTC

ok i will give that a try but i''m still curious to know why it works with selectall versus doubleclickoncell


PB Philip Bishop May 28, 2004 11:13 AM UTC

and by work i meant why doesnt the canceledit work like im assuming it should in both cases


AD Administrator Syncfusion Team May 28, 2004 11:53 AM UTC

After the edit i cancelled in the DoubleClick case, the focus goes back to the cell and the edit control in the cell does not have focus. This is why CurrentCell.CancelEdit works in this case. In the other case, the focus is returned to the same edit control you typed into (as you set e.Cancel = true). This control still reflects the last editing state. I think this is the problem. The work-around just sets the the proper value into this control so it reflects what you want it to reflect.

Loader.
Up arrow icon