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?
Found it,
I was binding the datatable to the grid by doing dgvWOVals.DataSource = <DataTable>, which overrides the schema. Therefore in the formula the Band key has to be replaced with the table name, so in my case that would be
"sum([//dgvWOVals/Valuations/MV] )"
instead of
"sum([//dgvWOVals/Band 0/MV] )"
Thanks for the reply, though.
What if I only want to sum certain rows in the column?
Say I have 10 rows in the column but only want to sum 5 of them and display it in a textbox? They do have a u_id, so how do I say "only sum these u_ids together"?
What you would do is create an unbound column in the grid and give it a formula using the "IF" function so that you give the unbound cell a value or 0 based on the u_id. Then you sum the unbound column.
Can you give me some sample code? I don't understand the formula of the grid and don't know how I can say:
Sum(if(u_id in (10.2, 10.3, 10.5, 10.6, 10.8, 10.9), 0, annual_spent))
Thanks....
You don't do Sum(If(... UltraGrid does not have a SUMIF or SUMPRODUCT the way Excel does.
You create an unbound calculated column with the formula if(u_id = X, annual_spent, 0)... Name it, say, Selected_annual_spent. Then in the textbox you say sum([//UltraGrid/BandName/Selected_annual_spent]).
Make sure your BandName is correct - if you're binding the grid to a datatable at run time, the band name is the table name.
Hope this helps
What data type is your Category_id ? If it is numeric, you shouldn't have quotes around the values.
ok, I figured out the syntax some but my formula still isn't working. Any ideas what is wrong?
This is my formula for the unbound column. It still includes all of the category_ids in the unbound column. I want it to not include the ones below (10.2, 10.3, 10.5, 10.6, 10.8, 10.9)....
if(and( [Category_id] <> "10.2" , [Category_id] <> "10.3" , [Category_id] <> "10.5", [Category_id] <> "10.6", [Category_id] <> "10.8", [Category_id] <> "10.9" ), [Annual_Spent_After], 0 )