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

ValidateFailed and CurrentCellAcceptedChanges problems

I have some problems with the CurrentCellAcceptedChanges and ValidateFailed events. I need to be able to enter both numbers and expressions into a databoundgrid with a column of double celltypes. The CurrentCellAcceptedChanges raises after the internal error from the grid saying that the entered value is not a valid double (for instance 25.0+30.0) The ValidateFailed event triggers just perfect in time but when I use the currentCell colindex and rowindex I found that it represents the next cell we have moved after pressing TAB or enter or similar. Can I somehow get hold of the last cell that holds my expression? /Tomas

8 Replies

AD Administrator Syncfusion Team November 3, 2005 01:49 PM UTC

ValidateFailed normally has the offending cell as the currentcell. Here is a simple sample showing this. http://www.syncfusion.com/Support/user/uploads/GDBG_CheckBox_de53c4ff.zip Are you handling other events that may try to position the current cell?


TO Tomas November 3, 2005 02:59 PM UTC

Ah yes, I listen to the CurrentCellKeyDown event to be able to control what should happen when leaving the cell depending on which button that was pressed - this event I presume raises first?. Is there any other events that I can use or how can I solve this? Btw, is there some list of all events and what order they fire available?


AD Administrator Syncfusion Team November 3, 2005 03:52 PM UTC

You could try this. In the CurrentCellValidating event, you can cache the CurrentCell.RowIndex and CurrentCell.ColIndex in some private variables. Then you could use these variables in ValidateFailed to get where the old current cell was. The samples in the \Essential Studio\3.3.0.0\Windows\Grid.Windows\Samples\CellTypes folder have an event log class that you can use to see a log of the currentcell events.


TO Tomas November 4, 2005 08:20 AM UTC

I have managed to get the correct information in the ValidateFailed event, the problem now is how can I store my evaluated expression back to the gridcell so that it won''t display the error: "35+45 is not valid for a Double". Setting e.Handled = true doesn''t seem to be enough. Niether to store the correct value into the StyleInfo.CellValue property. Any thoughts?


AD Administrator Syncfusion Team November 4, 2005 10:49 AM UTC

If your datasource expects a double, then you cannot put a string into the datasource. This means you cannot put a string into style.CellValue because that goes to the DataSource (the GridDataBoundGrid has no where else to put it). If you want to store extra information on a double column (like a formula string), then you will have to add some kind of datastore to manage this. In SaveCellInfo, you take the extra information and put it into your DataStore, and in QueryCellInfo, yougetthe information from the DataStore and put it into the cell. There may be problems trying to get this to work if you are sometimes putting a string into a Cell and sometime putting a double into a cell (and the underlying datasource requires a double). Take a look at this KB. It does something similar, storing additional information for cells. http://www.syncfusion.com/support/kb/grid/Default.aspx?ToDo=view&questId=104


TO Tomas November 4, 2005 11:02 AM UTC

Thanks for the information Clay, but this is not really what I intend to do. 1. If the user enters a double value it should be stored as usual. 2. If the user enters an expression, for instance 35+58 or 12*54*(3-5) then I want to evaluate this expression to a double value before storing it to the grid. I don''t need to store the expression itself. 3. If the user enters something else, for instance "hello" then the grid should show this error message saying its not valid. Now, the evaluation part is solved, I always get a double value in the end. My only problem is that I don''t understand how I can store this double value into the grid and say that validation is OK. (ie. I want to take care of the validation myself more or less)


AD Administrator Syncfusion Team November 4, 2005 11:18 AM UTC

You should try handling the CurrentCellvalidating event. There get the proposed string from grid.CurrentCell.Renderer.ControlText. If you get "14 + 15", then set grid.CurrentCell.Renderer.Control.Text = "29", and let the grid continue handling things. If you get "14" or "abc", then do nothing and just let teh grid handle it. (Notice in the above code, one place it is ControlText and the other it is Control.Text.)


TO Tomas November 4, 2005 01:45 PM UTC

Now it works just fine! Thank you Clay, you are my hero!

Loader.
Live Chat Icon For mobile
Up arrow icon