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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.

# Calculation problem

#### Replies:

101191 Oct 5,2011 08:54 AM UTC Oct 12,2011 12:01 AM UTC WinForms 1
 Subscribe to this post Tags: GridControl
Christoph Gasser
Asked On October 5, 2011 08:54 AM UTC

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?

Thank
Christoph Gasser

Arulraj A [Syncfusion]
Replied On October 12, 2011 12:01 AM UTC

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.

Regards,
Arulraj A

CONFIRMATION

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.