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

2 GridDataBoundGrid & A Syncfusion.Calculate.CalcEngine

Hi ,

I Have 2 GridDataBoundGrids which uses a single Syncfusion.Calculate.CalcEngine.

After adding some formulas in those two girds , how can i get those formulas back by giving the Grid or GridName from the CalcEngine engine.

Regards,
Sreekesh NK


2 Replies

AD Administrator Syncfusion Team July 29, 2008 11:35 PM UTC

Here is one way you can do it. Add a hashtable to track the ICalcDataObjects as keys and the SheetNames as values. Populate this hashtable when you call RegisterGridAsSheet.


private Hashtable parentObjectToSheetName = new Hashtable();


//...

engine.RegisterGridAsSheet("DG1", this.dataGrid1, sheetfamilyID);
parentObjectToSheetName.Add(this.dataGrid1, "DG1");
engine.RegisterGridAsSheet("DG2", this.dataGrid2, sheetfamilyID);
parentObjectToSheetName.Add(this.dataGrid2, "DG2");
engine.RegisterGridAsSheet("DG3", this.dataGrid3, sheetfamilyID);
parentObjectToSheetName.Add(this.dataGrid3, "DG3");
engine.RegisterGridAsSheet("DG4", this.dataGrid4, sheetfamilyID);
parentObjectToSheetName.Add(this.dataGrid4, "DG4");
engine.RegisterGridAsSheet("DG5", this.dataGrid5, sheetfamilyID);
parentObjectToSheetName.Add(this.dataGrid5, "DG5");
//...

//then to get the FormulaInfoTable, try code like this:

GridSheetFamilyItem family = CalcEngine.GetSheetFamilyItem(this.dataGrid1);

foreach (object key in engine.FormulaInfoTable.Keys)
{
FormulaInfo info = engine.FormulaInfoTable[key] as FormulaInfo;
string cell = key.ToString();
int loc = cell.LastIndexOf('!');
string sheetToken = cell.Substring(0, loc+1);
string sheetName = parentObjectToSheetName[family.TokenToParentObject[sheetToken]].ToString();
cell = cell.Substring(loc+1);
Console.WriteLine("sheet=[{0}] cell=[{1}] formula=[{2}]", sheetName, cell, info.FormulaText);
}




AD Administrator Syncfusion Team July 30, 2008 08:52 PM UTC

Hi ,
The code you have given is not working!!
Here also you are iterating through engine.FormulaInfoTable.Keys

foreach (object key in engine.FormulaInfoTable.Keys)

But this Keys is always the same irrespective of the grid.

I tired your code but it is not working.



>Here is one way you can do it. Add a hashtable to track the ICalcDataObjects as keys and the SheetNames as values. Populate this hashtable when you call RegisterGridAsSheet.


private Hashtable parentObjectToSheetName = new Hashtable();


//...

engine.RegisterGridAsSheet("DG1", this.dataGrid1, sheetfamilyID);
parentObjectToSheetName.Add(this.dataGrid1, "DG1");
engine.RegisterGridAsSheet("DG2", this.dataGrid2, sheetfamilyID);
parentObjectToSheetName.Add(this.dataGrid2, "DG2");
engine.RegisterGridAsSheet("DG3", this.dataGrid3, sheetfamilyID);
parentObjectToSheetName.Add(this.dataGrid3, "DG3");
engine.RegisterGridAsSheet("DG4", this.dataGrid4, sheetfamilyID);
parentObjectToSheetName.Add(this.dataGrid4, "DG4");
engine.RegisterGridAsSheet("DG5", this.dataGrid5, sheetfamilyID);
parentObjectToSheetName.Add(this.dataGrid5, "DG5");
//...

//then to get the FormulaInfoTable, try code like this:

GridSheetFamilyItem family = CalcEngine.GetSheetFamilyItem(this.dataGrid1);

foreach (object key in engine.FormulaInfoTable.Keys)
{
FormulaInfo info = engine.FormulaInfoTable[key] as FormulaInfo;
string cell = key.ToString();
int loc = cell.LastIndexOf('!');
string sheetToken = cell.Substring(0, loc+1);
string sheetName = parentObjectToSheetName[family.TokenToParentObject[sheetToken]].ToString();
cell = cell.Substring(loc+1);
Console.WriteLine("sheet=[{0}] cell=[{1}] formula=[{2}]", sheetName, cell, info.FormulaText);
}





Loader.
Live Chat Icon For mobile
Up arrow icon