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:
- 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.
- Extract summary values from a group row's summaries hashtable. The hashtable is obtained via the GetGroupSummaryValues method of the GridView.
- Obtain column coordinates from the grid's GridViewInfo object (see A2624). Calculate coordinates for the summary text.
- 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
Some clarifications of what we had to do to get this working for v 12.2:
Sublcassed GridView and hook up to CustomDrawGroupRow event, then in the event handler…
3.1 Select Unique GridGroupSummaryItem (could be multiple summaries, can only display 1)
3.2 Get row's bounds (incl level indent)
3.3 Fill with "sellected-row color" if row is selected
3.4 Draw Summary item
3.4.1 Get group summary text
3.4.2 Get cell bounds (using row and column bounds info)
3.4.3 Draw actual text using columns (header's font)
3.5 Draw expand/collapse buttons
3.6 Draw group caption
3.6.1 Get row's bounds (inc level indent)
3.6.2 Get group value text
3.6.3 Draw actual text using (row's font)
This really-really should be a feature - it is quite time consuming to piece all the information togetheryou should at least provide a complete code sample (inc printing/exporting functionality). I can't due to IP restrictions of my client.
Hi,
Please accept my apologies for the delayed response. We have two examples that demonstrate how to implement this functionality: How to align summary values displayed in a group row to the corresponding columns and How to print group summary values under corresponding columns. They are also available with v12.2.
Moreover, we have a ticket to implement this functionality out-of-the-box: GridView - Group row footer - add an ability to display footer summaries in a group row aligned to columns. However, I cannot tell you when it will be implemented.
I hope this information helps.
Hi All, I have implemented this solution and works pretty fine. The problem that I am facing and I don't know if you can replicate it is that the text get lost when switching between applications. If the control is focus you can see the text created but when you move out to another tab or application running in the machine the text will get lost. Is there any workaround this?
Thanks a lot.
Thank you.
I've created a new project from scratch and I wasn't able to replicate it until I added one line of code.
On the DrawSummaryValues method I added this line:
e.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Far;
Also, I added the grid into a tab control, and then changing between tabs back and forward makes the label for the first band to disappear.
I attached my test project.
Now, I am finding a way to do the alignment because is not working from the designer and neither the banded grid columns that I am creating dynamically. Any help on this will work.
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
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.