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

Where or how to write code to calculate cell value according to other cell''s values

In GridGroupingControl, I have cells "Area", "Length","Width". "Area" should be calculated by "Length * Width". Whenever Length or Width was changed, the "Area" should be recalculated using the formula. I don''t know where or how to write the code ? TIA

5 Replies

AD Administrator Syncfusion Team August 31, 2004 09:27 AM

You would add an ExpressionFieldDescriptor to create a column that is the product of two existing columns. You can do this from the designer or from code. This is discussed in the Essential Grid>User Guide>Essential GridTutorials>GridGroupingControl tutorial. From code, it would look something like: ExpressionFieldDescriptor exp = new ExpressionFieldDescriptor("Area", "[Length] * [Width]"); this.gridGroupingControl1.TableDescriptor.ExpressionFields.Add("Area");


AD Administrator Syncfusion Team August 31, 2004 11:51 AM

Hi Clay, Thanks for the reply. I was hoping that I could use the gdBase_TableControlCurrentCellValidating or gdBase_TableControlCurrentCellValidated events to perform the calculation. I''ve tried to put code into each event that would get the current values from the appropriate cells, but cannot seem to return the correct values. How do I get the current cell and other cell''s values by column name? Should I be doing it this way or should I try to read the values from the bound table? Regards. >You would add an ExpressionFieldDescriptor to create a column that is the product of two existing columns. You can do this from the designer or from code. This is discussed in the Essential Grid>User Guide>Essential GridTutorials>GridGroupingControl tutorial. From code, it would look something like: > >ExpressionFieldDescriptor exp = new ExpressionFieldDescriptor("Area", "[Length] * [Width]"); >this.gridGroupingControl1.TableDescriptor.ExpressionFields.Add("Area"); >


AD Administrator Syncfusion Team August 31, 2004 12:46 PM

I would probably try working with the datasource directly. Here is some code from a KB that gets at the DataRow.
private void grid_TableControlCurrentCellValidating(object sender, GridTableControlCancelEventArgs e)
{
	int row = e.TableControl.CurrentCell.RowIndex;
	Element el = e.TableControl.Table.DisplayElements[row];
	Record r = el.ParentRecord;
	int dataRowPos = e.TableControl.Table.UnsortedRecords.IndexOf(r);
	DataRow dr = parentTable.Rows[dataRowPos];
	Console.WriteLine(dr[0].ToString() + dr[1].ToString() + dr[2].ToString());
}


AD Administrator Syncfusion Team August 31, 2004 12:55 PM

I noticed that you did this in the grid_TableControlCurrentCellValidating event. Would the datasource be updated at this point or should I use the grid_TableControlCurrentCellValidated event? >I would probably try working with the datasource directly. Here is some code from a KB that gets at the DataRow. >
>private void grid_TableControlCurrentCellValidating(object sender, GridTableControlCancelEventArgs e)
>{
>	int row = e.TableControl.CurrentCell.RowIndex;
>	Element el = e.TableControl.Table.DisplayElements[row];
>	Record r = el.ParentRecord;
>	int dataRowPos = e.TableControl.Table.UnsortedRecords.IndexOf(r);
>	DataRow dr = parentTable.Rows[dataRowPos];
>	Console.WriteLine(dr[0].ToString() + dr[1].ToString() + dr[2].ToString());
>}
>


AD Administrator Syncfusion Team August 31, 2004 01:11 PM

Everything except the current cell shoul dbe updated. You can get the CurrentCell value with: string s = e.TableControl.CurrentCell.Renderer.ControlText;

Loader.
Live Chat Icon For mobile
Up arrow icon