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
519
Adding row count to summary in customised grid.
posted

Hi ,

I need to add row count to the summaries in the customised grid such that

it should display in the caption the number of rows in the grid as well as if it is filtered

and

In addition to this it needs to preserve the existing caption if any.

Can somebody suggest me .

Thanks,
Ashish.

Parents
  • 69832
    Offline posted

    I wasn't able to figure out how to preserve the existing caption, but I think it is just "Summary: x" or "Total: x" or something like that. The following code sample demonstrates how to use the ICustomSummaryCalculator interface to show the number of rows along with the summary value:

    this.ultraGrid.DisplayLayout.Override.SummaryDisplayArea = SummaryDisplayAreas.BottomFixed;           
    this.ultraGrid.DisplayLayout.Bands[0].Summaries.Add(
        SummaryType.Custom,
        new CustomSummaryCalculator(),
        this.ultraGrid.DisplayLayout.Bands[0].Columns["UnitsInStock"],
        SummaryPosition.UseSummaryPositionColumn,
        this.ultraGrid.DisplayLayout.Bands[0].Columns["UnitsInStock"] );

    public class CustomSummaryCalculator : ICustomSummaryCalculator
    {
        private int total = 0;

        void ICustomSummaryCalculator.AggregateCustomSummary(SummarySettings summarySettings, UltraGridRow row)
        {
            object value = row.Cells[summarySettings.SourceColumn].Value;
            if ( value is short )
                this.total += (short)value;
        }

        void ICustomSummaryCalculator.BeginCustomSummary(SummarySettings summarySettings, RowsCollection rows)
        {
            this.total = 0;
        }

        object ICustomSummaryCalculator.EndCustomSummary(SummarySettings summarySettings, RowsCollection rows)
        {
            summarySettings.Lines = 2;
            summarySettings.DisplayFormat = "{0}";
            return string.Format("Total: {0}{1}Rows: {2}", this.total, Environment.NewLine, rows.Count);
        }
    }

Reply Children