I have a WinGrid with two bands. The second band contains summary rows in each group (just simple SUM rows). I need to check that the SUM value does not exceed 100.
I cannot find anything in the documentation or forums to show how to access the value calculated in the summary row before a user saves the data. I saw something about casting the summary row to an UltraGridGroupRow - but this throws an exception ("Unable to cast...").
UltraGridGroupByRow gbr = (UltraGridGroupByRow)row;
object s = gbr.Rows.SummaryValues["Sum"].Value;
This is the correct way to do it. If you are getting an exception when casting to a GroupByRow, then the row must not be a GroupbyRow. So either you are not grouping, or you are usng the wrong row. Or maybe you are trying to access the row before the grid has been grouped. Check the row.IsGroupByRow property to see if the row is a GroupByRow or not.
Hi Mike
I am not following the terminology here - I understand a "group" as something you create to consist of one or more columns in a grid. By groups are you referring to the bands? My grid basically contains parent/child data, where each row in Band[0] expands to show child rows in Band[1]. There is a summary row added to Band[1], so a SUM value is displayed to summarize each child row section - and this is the value I need to get.
Can you please help clarify this?
Okay... Groups and GroupByRows are two different things. When you said Group, I assumed you were talking about using a grid with a ViewStyleBand set to OutlookGroupBy, because doing so would make getting the summaries a little more complex. Groups have no relevance to summaries, so when you mentioned them, I assumed you must be talking about GroupByRows, since Groups don't matter.
Anyway... you don't need to cast anything in this case, you just need to get a child rows collection for whatever island of data you want the summary value for. How you do that depends on what summary values you want.
But just for example, let's say you want the summary value of the children of the first row in the grid. You would do something like this:
grid.Rows[0].ChildBands[0].Rows.SummaryValues[0].Value
The 0's here are just arbitrary for the first item. You can also use keys, of course.