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.

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

Thread ID:

Created:

Updated:

Platform:

Replies:

18437 Aug 31,2004 08:16 AM Aug 31,2004 01:11 PM Windows Forms 5
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On August 31, 2004 08:16 AM

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

Administrator [Syncfusion]
Replied On 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");

Administrator [Syncfusion]
Replied On 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"); >

Administrator [Syncfusion]
Replied On 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());
}

Administrator [Syncfusion]
Replied On 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());
>}
>

Administrator [Syncfusion]
Replied On 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;

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.

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.

;