Hi Clay,
I am working on SummaryGrid. The problem is that one of the main grid columns is FormulaCell. When in SummaryGrid the sum is calculated for that column, the value of the cell which I get as grid.Model[row, col].Text is a formula itself, not a value. So how to get the value of the FormulaCell?
Tnanks
AD
Administrator
Syncfusion Team
August 8, 2004 06:03 AM UTC
To get the formula value instead of the formula string, try using grid[row, col].FormattedText.
IR
Irina
August 8, 2004 02:18 PM UTC
It works fine when summary grid is shown first time. Then if I change the cell value, the summary value on summary grid for that column is updated; my formula cell on main grid is updated too, but how to force the summary grid column for formula cell to update? In SaveCellInfo of summary grid I use
string s = (row == e.RowIndex)
? e.Style.Text : this.grid.Model[row, e.ColIndex].FormattedText;
Cannot use e.Style.FormattedText – the program is hanging.
Thanks
AD
Administrator
Syncfusion Team
August 8, 2004 06:48 PM UTC
In SaveCellInfo, you can get the computed value from e.Style.FormulaTag.Text.
IR
Irina
August 8, 2004 08:02 PM UTC
But it is still hanging...Something wrong with my code? I have a column index = 8 for formula cell and I have changed the code of SaveCellIfo like that:
else if(type == SummaryType.Sum)
{
double d = 0;
try{
for(int row = 1; row < this.grid.Model.RowCount; ++row)
{
string s = "";
if (row == e.RowIndex)
{
if (e.ColIndex == 8)
s = e.Style.FormulaTag.Text;
else
s = e.Style.Text;
}
else
s = this.grid.Model[row, e.ColIndex].FormattedText;
d += double.Parse((s.Length > 0) ? s : "0");
}
}
catch
{d = 0;}
this.summaryGrid[1, e.ColIndex].CellValue = d;
}
Thanks
AD
Administrator
Syncfusion Team
August 8, 2004 08:10 PM UTC
If grid is a GridDataBoundGrid, the SaveCellInfo should save e.Style.Formulatag in some datastructure. Then in your QueryCellInfo handler, you should retrieve the saved FormulaTag object and set it to e.StyleFormulaTag based on e.RowIndex and e.ColIndex as in the KB article.
This normally avoids the lockups caused by having constantly recompute the formulas when the FromulaTags are not being saved.
IR
Irina
August 8, 2004 08:53 PM UTC
Yes, I do exactly what you say in SaveCellInfo and QueryCellInfo of the main grid, but it is not clear about SaveCellInfo of summary grid class which is raised as a main grid event. How both SaveCellInfo is related and how to refresh the formula column in summary grid SaveCellInfo?
Thanks
AD
Administrator
Syncfusion Team
August 8, 2004 09:23 PM UTC
Are you using a GridControl like in the KB summary row sample as the summary grid? If so, the SaveCellInfo handler in the Summary grid is teh main''s grid event like you say. Its purpose is to tell the summary grid that a cell was changed in the main grid. The handler should take the changed value (from the event args) and use it to conmpute the new summary values that it needs to display in the summary grid. To set the newly computed value in the summary grid, you should use the indexer on the summary grid to save the newly computed value. The sample from the KB directly computes the new values. It does not try to use a formula cell. Are you trying to use a formula cell in the summary grid that depends on values from the main griddataboundgrid? If so, I am not sure this will work. You might try computing the summaries as in the sample that does not try to use formula cells in the summary grid.
IR
Irina
August 8, 2004 10:21 PM UTC
Yes, I need a formula cell in the summary grid that depends on values from the main databoundgrid. And in addition I have two databound grids on the tabpage. Each of grids has formula column which is gorizontal totals. Each of them should have summaryRow where one column is sum of formulas and plus it should be one more grand total summaryRow grid.
I tried create a summaryType for formula column - doesn''t work as you say. I want to try summaryType which computes sum of all rows and columns in main grid. But I have no idea how to handle those nested "for(...){...}" statements in SaveCellInfo. What is your suggestion?
Thanks
AD
Administrator
Syncfusion Team
August 9, 2004 05:48 AM UTC
It is possible to have cross references in our formula engine, but that has only been tested with GridControls.
Here is code that I think will look through and sum all cells in a GridDataBoundGrid, event if some cells are FormulaCells. It uses a helper method to isolate he code that gets the string from the style.
double sum = 0;
//assumes an AddNew row - if you don''t have one, use <=.
for(int row = 1; row < this.mainGrid.Model.RowCount; ++row)
{
for(int col = 1; col <= this.mainGrid.Model.ColumnCount; ++col)
{
GridStyleInfo style = this.mainGrid[row, col];
string val = GetValueFromFormulaStyle(style);
double d;
if(double.TryParse(val, NumberStyles.Any, null, out d))
{
sum += d;
}
}
}
private string GetValueFromFormulaStyle(GridStyleInfo style)
{
string val = style.Text;
if(style.CellType == "FormulaCell")
{
if(style.FormulaTag != null&& style.FormulaTag.Text.Length > 0)
{
val = style.FormulaTag.Text;//used already calculated value
}
else
{
val = style.FormattedText;//trigger calculation
}
}
return val;
}
IR
Irina
August 9, 2004 12:16 PM UTC
Thanks Clay,
It works perfect for my two main grids and their two summaryRow grids. Now I am trying the third summaryRow which is grand total for those two.
Thanks again