Calculation problem

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


1 Reply

AA Arulraj A Syncfusion Team 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.
http://www.syncfusion.com/uploads/redirect.aspx?&team=support&file=GDBG_3-704780279.zip

Please let us know if you have any further concerns.

Regards,
Arulraj A



Loader.
Up arrow icon