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
All you do is create an unbound column in the grid and apply a formula to it. Here's some sample code. In this sample, the unbound column formula checks the Value of the column names "Int32 1" and if it's a 1, assigns the value of the "Int32 2" column to the unbound column, otherwise, it assigns a 0.
Then the TextBox or label or whatever can simply sum the unbound column.
private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e) { UltraGridColumn myUnboundColumn = e.Layout.Bands[0].Columns.Add("My Unbound Column"); myUnboundColumn.DataType = typeof(int); myUnboundColumn.Formula = "IF ( [Int32 1] = 1, [Int32 2], 0 )"; //myUnboundColumn.Hidden = true; }
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 )
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
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....