Hi!
I'm using the UltraGrid (in namespace Infragistics.Win.UltraWinGrid) and I want to sum all the values (integers) in a certain column in the grid and put the result in a textbox (not in an extra row in the grid!). How do I do that?
I'm using version 6.2.
Regards, Emelia
Hi,
I had the same issue last week and SummaryRows weren't the solution as they have to be visible in order for them to recalculate. I'd suggest using the UltraCalcManager and supplying a named reference and a formula to it. This should give you the column sum you need.
Regards, Mark
Which methodes/properties shall I use to supply the UltraCalcManager with a named reference and a formula?
Add the UltraCalcManager to your form
Add a NamedReference to the UltraCalcManager NamedReferences collection. The formula will be something like sum( [//_grid/DataRecord/Qty] ), where "_grid" is the Id of the Grid, DataRecord is the Band name and Qty is the Column name.
_calcManager.NamedReferenceResultChanged += new Infragistics.Win.UltraWinCalcManager.NamedReferenceResultChangedEventHandler(OnSumQty_NamedReferenceResultChanged);
In the event handler, update your control
{
_sumQtyLabel.Text = e.NamedReference.FormulaResult.ToString();
}
I figured it out. When you want hidden rows included in the calculation you need to set the Override.FormulaRowIndexSource to FormulaRowIndexSource.Lstindex on the actual ultrawingrid.
I have implemented a calculated column and it works fine but it has rasied another issue. Is there any way to get the calcmanager to run it calculations against hidden records (hidden=true;)
I was assuming that the actual calcmanager iterated through the individual rows as part of the SUM function. If it did, it would have a context for referencing an individual row and be able to evaluate my IF statement base on another column value in the same row, rather than the whole column as you mentioned above.
I had better add my calculated column.......
As I stated above, there is no way to do this with a single formula. You must use 2 formulas.
References in any formula are relative to the object to which the formula is being applied.If you are applying a formula to a grid column, then referencing another column really references the cell in the column in the same row as the cell whose formula is being calculated.
For example, if I have two columns in the grid called "Column 0" and "Column 1", then when I apply a formula to "Column 1" that references "[Column 0]", each cell in column 1 has a context (the row) by which it can get a corresponding cell in Column 0.
For a textbox, there is no such context. So if a TextBox refers to "Column 0", the reference represents the entire column. Therefore, in a TextBox, doing something like "if ([Column 0] > 10, [Column 0], 0)" is meaningless. Asking if a column is greater than 0 is a meaningless condition, as Column 0 is not a value, it's a list of cells.
Mike,
I hear what you are saying about adding the calculated field and summing it, but this is surely a long winded way...I basically have the same issue as tammy in that i am trying to carry out a conditional sum based on a simple expression. For instance on my text box the following will work
SUM([//gdBillCallsGrid/ConnectionBillCalls/CallCost])
but I cannot get the following to work
SUM(if([//gdBillCallsGrid/ConnectionBillCalls/CallCost] >10,[//gdBillCallsGrid/ConnectionBillCalls/CallCost],0))
I get "Incorrect type of argument or operand"