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.

Problem with % in Formulas

Thread ID:





63248 Jun 30,2007 01:16 AM Jul 3,2007 05:23 AM Windows Forms 4
Tags: Calculate
Ben Fraser
Asked On June 30, 2007 01:16 AM


I am on 5.1 final.

The formula =SUM($H$1:H15)*C17% which I am tracking via a CalcEngine and displaying in a GridControl is throwing an "invalid expression" error. Entering the same formula directly in a GridControl with FormulaCells


Administrator [Syncfusion]
Replied On July 2, 2007 03:33 AM

I think your post might have been truncated for some reason. And the sample does not show any use of Calculate. Could you repost your question and explain how to see the problem in the sample you uploaded?

I did paste the formula you provided in our \Windows\Calculate.Windows\Samples\2.0\GridDataBoundGridCalculator sample and it does not work there. The reason is that currently Essential Calculate does not recognize the % as a unary operator. The only unary operator recognized by Essential Calculate is the unary minus. Depending upon your exact use case, you may be able to tweak your ICalcData implemetation to handle (or at least avoid the error from) a unary % operator. If you post a sample showing your use case, maybe we can suggest something.

Ben Fraser
Replied On July 2, 2007 07:37 PM

My apologies, the truncation may be due to trying out Safari on Windows but attaching the wrong example was my fault.

If you open this example and enter =SUM($H$1:H15)*C17% into a cell you will see the error.

Avoiding the problem isn't really an option, we want Excel formula compatibility.

I assume from your reply that GridControls use a specialise CalcEngine in the background? Is it possible to access that one in my code? Can you point me to the location in the source where this is implemented?



Administrator [Syncfusion]
Replied On July 3, 2007 05:21 AM

Below is your sample back with an example of what I had in mind when I susgested tweaking the ICalcData implementation. I added an Engine reference to ArrayCalcData and tweak the code in SetValueRowCol to handle the %, turing it to a / 100 so the computed values will reflect the entered % formula. This may not serve your needs though as it steps on the actual formula being set.

The CalcEngine class in Essential Calculate and the GridFormulaEngine class in Essential Grid are not directed related as derived classes but they do share a significant amount of code. In general, if you are using grid classes, then using the GridFormulaEngine is a better fit (though when using virtual GridControls or GridDataBoundGrids, you lose some of the direct support of maintaining the style.FormulatTags - but generally this can be handled via QueryCellInfo and SaveCellInfo).

I am not sure exactly what featues of a GridFormulaEngine you need, but given a string starting with an =, you can parse it using engine.Parse. You can then compute the parsed formula with engine.ComputedValue. To get a reference to the GridFormulaEngine associated with a GridControl, you use

GridFormulaEngine engine = ((GridFormulaCellModel)grid.CellsModels["FormulaCell"]).Engine;

To get at a particular cells' formula, you use grid[row, col].Text. To get at a particular cell's computed value, you can use grid[row, col].FormattedText. The engine.IsFormulaValid method exposes ways of testing formula syntax in grid.CurrentCellValidating (for example).

If this is not the information you need on using the GridFormulaEngine, please ask further questions on it.

Administrator [Syncfusion]
Replied On July 3, 2007 05:23 AM

I forgot to upload the modified sample. Here it is.



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.

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.