KB Article A1041
Visible to All Users

How to align summary values displayed in a group row to the corresponding columns

Description:
I would like to show group summaries in the group row, aligned with the columns they relate to. Is there a way to achieve this?

Answer:
[UPDATE]
We've introduced the GridView.OptionsBehavior.AlignGroupSummaryInGroupRow property in v15.2. Enabling this option allows you to align group summaries in a group row under the corresponding columns out of the box. See the GridOptionsBehavior.AlignGroupSummaryInGroupRow Property help topic for more information.

[Applied for v15.1 and earlier]

The XtraGrid does not support this feature, but you can implement it by using the CustomDrawGroupRow event. Please note, there may be not enough space to show a summary value for the first grid column, because group values are displayed in group rows besides summaries. The XtraGrid provides group row footers which are especially designed for displaying group summaries under the corresponding columns. We advise you to consider this option prior to implementing the solution explained below. If you wish to display summaries even if group rows are collapsed, please set the GridView.GroupFooterShowMode property to VisibleAlways. Please see the Group Summary topic in regard to seting up group summaries.
To show group summaries in a group row aligned with columns, you should handle the GridView.CustomDrawGroupRow event and draw the entire row's interior. This is a complex task and includes the following steps:

  1. Remove the summaries from a group row's caption and paint it using the default drawing classes. You will need to use the e.Painter and e.Info parameters of CustomDrawGroupRow.
  2. Extract summary values from a group row's summaries hashtable. The hashtable is obtained via the GetGroupSummaryValues method of the GridView.
  3. Obtain column coordinates from the grid's GridViewInfo object (see A2624). Calculate coordinates for the summary text.
  4. Draw values and finally set the e.Handled parameter to True to prevent the grid from drawing the group row itself.
    You may wish to improve our code for the CustomDrawGroupRow event handler to prevent overpainting of a group button when the first column width is reduced or the grid has frozen columns.

See this GitHub example for sample code:
How to align summary values displayed in a group row to the corresponding columns

See Also:
A2624
How to print group summary values under corresponding columns

Show previous comments (4)
Yaroslav (DevExpress Support) 12 years ago

    Andres,
    I have posted a new ticket on your behalf regarding your question: Q378956

      Hi

      Was the issue with the disappearing group label when changing Tabs solved?

      I cannot see the question regarding to Q378956 as it was not made public if the issue was resolved here.

      Many Thanks Tom

      DevExpress Support Team 8 years ago

        Hello,

        I've created a separate ticket on your behalf (T448870: Disappearing group label when changing Tabs issue). It has been placed in our processing queue and will be answered shortly.

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.