Hello!
I have and ultragrid filled with data that can be shown in three different ways.
1. Not grouped at all, just rows straight from the source.
2. One level of grouped data.
3. Two levels of grouped data.
In the initializelayout event of the grid, I have included code to add the summaries to the grid.
I have used
SummaryDisplayArea =
SummaryDisplayAreas.BottomFixed + SummaryDisplayAreas.GroupByRowsFooter
First of all, how can I get the values of the different summary cells? I will need to get these values, no matter how the data is grouped.
Secondly, is there a way to get some sort of label in front of each summary cell? I tried to se the
SummaryFooterCaptionVisible to true but I could only get the label above the summary cell. I would like to have i just to the left of the summary cell.
All other ideas that could help me get this grid look even better are more than welcome...
Thanks!
/Henrik
Hi Henrik,
Zlatan said:First of all, how can I get the values of the different summary cells? I will need to get these values, no matter how the data is grouped.
The summary value can be retrieved from the rows collection. Something like this:
grid.Rows.SummaryValues["my summary"].Value
This will work in a flat grid, because the summary is on the root rows collection. It will also work in a grouped grid. The grid maintains the root-level grand total summaries, even though you are not displaying them - at least it did in my testing using the built-in summary types. I didn't try it using formulas, so that might be different.
If you want the summary value of a set of child rows under a grouping, then you would have to get the rows in that group and access it's SummaryValues collection. So that means casting the root-level row (or possibly the first two levels, depending on how many levels of grouping you have) to an UltraGridGroupByRow. Then you can get the Rows collection of that group by row and using the SummaryValues collection just as above.
Zlatan said:SummaryFooterCaptionVisible to true but I could only get the label above the summary cell. I would like to have i just to the left of the summary cell.
There's no way to put in a label cell or something like that. But you can use the SummaryValue.DisplayFormat to preface the summary value with some text. The default is something like "Sum = {0}". But you can change this to whatever you want and use "{0}" as the replacement code for the value.
Thanks Mike!
I tried your approach on the first question but I cannot get any hits when it comes to UltraGridGroupByRows. I tried but none of the rows seems to be
"isgroupbyrow" or ends up in my last if-statement. This code is executed after I have bound my datasource to the grid.
For Each r As UltraGridRow In grdSpecification.Rows
Dim g As UltraGridGroupByRow
Try
g =
TryCast(r, UltraGridGroupByRow)
Catch ex As Exception
End Try
If Not g Is Nothing Then
Dim str As String = ""
End If
Next
If your grid is grouped, then every root-level row will be a GroupByRow.
So either you have no grouping applied when this code executes, or else the grid hasn't painted, yet, so the grouping hasn't been performed. Try calling grid.Update before your loop. That will force the grid to paint and therefore group.
Sorry for my late reply. You were correct, I placed the code in the wrong position when testing it, so the grouping wasn't applied.
I have got all my summary values using your approach with casting UltraGridRows to UltraGridGroupByRows, when IsGroupByRow is true for specific rows.