Display row count on Infragistics Ultragrid Winforms

user717560 picture user717560 · Nov 1, 2011 · Viewed 10k times · Source

What is the best way to display number of rows that an UltraGrid is bound to?

I want to be able to do, this.UltraGrid.DataSource = myCustomObject;

And, the grid should display the data along with the number of rows.

I tried to write a custom control with an ultragrid and a status bar. Update the status bar with rowCount when "InitializeRow" event is fired. This will give me what I want but this is very inefficient.

I have tried other events like "InitializeLayout", "InitializeRowsCollection","Enter" events but when the datasource changes these event doesn't get fired.

Suggestions?

Answer

user717560 picture user717560 · Nov 1, 2011

I found a better way to do this by using SummaryDisplayArea feature of ultragrid. http://help.infragistics.com/Help/NetAdvantage/WinForms/2011.1/CLR2.0/html/Infragistics2.Win.UltraWinGrid.v11.1~Infragistics.Win.UltraWinGrid.UltraGridOverride~SummaryDisplayArea.html

On InitializeLayout event I have something like this

        e.Layout.Override.AllowRowSummaries = AllowRowSummaries.True;

        UltraGridColumn columnToSummarize = e.Layout.Bands[0].Columns[0];
        SummarySettings summary = e.Layout.Bands[0].Summaries.Add("Count", SummaryType.Count, columnToSummarize);
        summary.DisplayFormat = "Number of Rows: {0:N0}";

        e.Layout.Override.SummaryDisplayArea = SummaryDisplayAreas.BottomFixed;
        e.Layout.Override.SummaryDisplayArea |= SummaryDisplayAreas.GroupByRowsFooter;
        e.Layout.Override.SummaryDisplayArea |= SummaryDisplayAreas.InGroupByRows;

        summary.SummaryDisplayArea = SummaryDisplayAreas.BottomFixed | SummaryDisplayAreas.GroupByRowsFooter;
        e.Layout.Override.GroupBySummaryDisplayStyle = GroupBySummaryDisplayStyle.SummaryCells;

        e.Layout.Override.SummaryFooterAppearance.FontData.Bold = DefaultableBoolean.True;
        e.Layout.Override.SummaryFooterCaptionVisible = DefaultableBoolean.False;