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.

Calculation problem

Thread ID:





101191 Oct 5,2011 04:54 AM Oct 11,2011 08:01 PM Windows Forms 1
Tags: GridControl
Christoph Gasser
Asked On October 5, 2011 04:54 AM

I've a data bound grid looking like this:

ValueA 100
ValueB 200
Total 300

I'd like to use formulas the way that when someone changes one of the values the Total is calculated (that's easy to do). But when someone changes the Total the ValueA and ValueB should be changing as well (when 300 is changed to 150 the values should be 50 and 100).

Is it anyhow possible to do this with the Syncfusion Grid control?

Christoph Gasser

Arulraj A [Syncfusion]
Replied On October 11, 2011 08:01 PM

Hi Christoph,

Thanks for your interest in Syncfusion products.

You can achieve your desired behavior by using CurrentCellValidating and PrepareViewStyleInfo events with respective codes. The following code explains the same.

void gridDataBoundGrid1_CurrentCellValidating(object sender, CancelEventArgs e)
GridCurrentCell gcc = this.gridDataBoundGrid1.CurrentCell;
if (gcc != null && gcc.ColIndex == this.gridDataBoundGrid1.Binder.NameToColIndex("Col2"))
double value;
Double.TryParse(gcc.Renderer.ControlText, out value);
this.gridDataBoundGrid1[gcc.RowIndex, 1].CellValue = value / 3;
this.gridDataBoundGrid1[gcc.RowIndex, 2].CellValue = (value / 3.0) * 2;

void gridDataBoundGrid1_PrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e)
if (e.RowIndex > 1 && e.ColIndex == this.gridDataBoundGrid1.Binder.NameToColIndex("Col2"))
double val1 = Double.Parse(this.gridDataBoundGrid1[e.RowIndex, this.gridDataBoundGrid1.Binder.NameToColIndex("Col0")].Text);
double val2 = Double.Parse(this.gridDataBoundGrid1[e.RowIndex, this.gridDataBoundGrid1.Binder.NameToColIndex("Col1")].Text);
double result = val1 + val2;
e.Style.CellValue = result;

Here is a sample for your reference.

Please let us know if you have any further concerns.

Arulraj A


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.