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

Formula engine values

Hi,

Is it possible to override the values that the formulae engine receives? (It doesn't look like you can override any of the members in GridFormulaEngine).

I have a custom property that holds a 'percentage object' and a custom cell model with an overidden OnPrepareViewStyleInfo method that facilitates percentage formatting so that e.g. 10 % is formatted as 10.00 (without the % sign) but the value of the 'percentage object' is actualy 0.10.


All operations in our app refer to the custom property's 'percentage object' value property.
This works fine except that formulae return cell value. If we could override the way the formula engine gets its values so that it interrogates the custom preperties first, then this would not be an issue.

Alternatively, is there an easy way of formatting a percentage without the "%" character?
I do not want to change the system's CultureInfo object as I want to choose which cells show "%" and which show withount "%" character.

1 Reply

HA haneefm Syncfusion Team October 5, 2007 11:39 PM UTC

Hi steve_randomno,

There are special formatting events that you could use to control the formatting. The events are QueryCellFormattedText and DrawCellDisplayText event. Below are some snippets that show how to customize the formating of the cells in a grid.

private void GridDrawCellDisplayText(object sender, GridDrawCellDisplayTextEventArgs e)
{
if(e.Style.CellType = "FormulaCell" && e.DisplayText != null && e.DisplayText != string.Empty )
{
double dvalue = Double.Parse(e.Style.CellValue.ToString());
e.DisplayText = String.Format("{0:#,##0,,.0MB}",dvalue) ; //Your Format
}
}

private void GridQueryCellFormattedText(object sender, GridCellTextEventArgs e)
{
if (e.Style.CellType == "FormulaCell" )
{
string s = e.Style.Text;
double dvalue = Double.Parse(e.Style.CellValue.ToString());
e.Text = String.Format("{0:#,##0,,.0MB}",dvalue) ; //Your Format
e.Handled = true;
}
}

Best regards,
Haneef

Loader.
Live Chat Icon For mobile
Up arrow icon