Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
250
Help Grouping and Summarizing in WinGrid
posted
Company ID Col1 Col2 Col3 Col4
Comp1 CC1C 90000 ASDF1 15 2
ASDF2 10 1
Total CC1C     25 3
Grand Total sum sum

I have pasted this table here to show a loose example of what I'm trying to do. I'm new to Grouping/Summarizing with Infragistics and need some tips.

In the case above there are 2 rows for Comp1 in the accompanying DataTable. The ID and Col1 values are the same for both of these rows. Then they have different values for Col2 as can be seen.

There is a "Total" at the bottom of every row in this Grid that sums Col3 and Col4. Then a Grand Total at the bottom of the Grid that sums these columns for every row.

There could be any number of rows for every Company. There were just 2 in this example. There can even be only 1 but the total will still display.

Any ideas how I should approach this problem?

I've tried adding the Company column to SortedColumns but end up with headers above every row rather than just at the top and I want the Company cells to merge together like is seen with "Comp1" above.

Is what I'm looking for possible? Or something close at least?

Parents
  • 469350
    Suggested Answer
    Offline posted

    Hi Caleb,

    In order to get a summary for each company, you would need to group by that company and thus introduce another level in the hierarchy. There's no way to insert a summary into the middle of a rows collection like you have in your mockup here.

    Having said that, I think it should be pretty simple to get very close to what you have here. I have attached a small sample project here with a quick attempt to get as close as possible to your mockup.

    Actually, I made some decisions that don't exactly match the mockup, but which I thought were better. :)

    For example, I put the summaries into the GroupByRow itself, in addition to having them at the bottom of each group. You could turn these off easily enough by removing the InGroupByRows flag from the SummaryDisplayArea property, if you like. In fact, you might want to play around with the various SummaryDisplayArea options, anyway, just to see which one(s) work best for your needs.

    And here's the relevant code:


            private void ultraGrid1_InitializeLayout(object sender, InitializeLayoutEventArgs e)
            {
                var layout = e.Layout;
                var band = layout.Bands[0];
                var ov = layout.Override;

                // In order to provide a summary for each company, you need to group by the company.
                var companyColumn = band.Columns["Company"];
                layout.ViewStyleBand = ViewStyleBand.OutlookGroupBy;
                band.SortedColumns.Add(companyColumn, false, true);

                // Add a summary for column 3.
                var column3 = band.Columns["Col3"];
                band.Summaries.Add(SummaryType.Sum, column3);

                // Add a summary for column 4.
                var column4 = band.Columns["Col4"];
                band.Summaries.Add(SummaryType.Sum, column4);

                ov.SummaryDisplayArea =
                    SummaryDisplayAreas.InGroupByRows | // This will give us summaries in the GroupByRow itself
                    SummaryDisplayAreas.BottomFixed | // This will give us a grand total at the bottom.
                    SummaryDisplayAreas.GroupByRowsFooter // This will give us a summary under each GroupByRow
                    ;

                // Make the summaries in the GroupByRow appears as cells instead of just raw text.
                ov.GroupBySummaryDisplayStyle = GroupBySummaryDisplayStyle.SummaryCells;           
            }

    InGroupByRows

    WindowsFormsApplication9.zip
Reply Children