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

Conditional formulas in a Grid?

I have a formula in a Grid which works out a percentage increase. =(A1-B1)/A1 The problem is obviously, if A1 is zero, it brings up an error. Does Essential Grid support if statements in the formula like excel? (can't see anything in the documentation) If not, does anyone know a way which I can get around this? Regards Mac

3 Replies

AD Administrator Syncfusion Team March 2, 2003 10:45 PM UTC

Exactly, what do you want to see when you divid by zero? Right now your formula shows the word 'Infinity' representing a value obtained when you divide by zero. Do you want to change the word 'infinity' to something else? Or do you want to change the zero to some other value or something of that nature so you always see a number is that cell. To change the zero to some other value, you could write a custom function that handled, so a function names CheckIfZero. This function would eithe rreturn the value of the calculation if nonzero, and the other value if it is zero. To change the word, you could handle PreviewStyleInfo and swap it out there. If you will explain exactly what you want to see in the cel, I could try to post some code snippets.

MA Mac March 3, 2003 08:29 PM UTC

Hi Instead of having infinity being shown, in this example I would like to have a 0 being shown. This could 0 or something else, for example, in another grid, I would like to have 100 (as in 100%) being shown. Any help would be appreciated Mac

AD Administrator Syncfusion Team March 3, 2003 09:46 PM UTC

The simplest way to do this is to handle the PrepareViewStyleInfo event, and swap out the Inifinity there.
private void gridControl1_PrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e)
	if(e.Style.FormattedText == "Infinity")
		e.Style.Text = "0";

Live Chat Icon For mobile
Up arrow icon