Sometimes it's necessary to specify a way of calculating summaries that is different from the default one. Assume you don't want to take into account cells with no data when calculating summaries. It's possible to accomplish this task using two events: use the GridView.CustomSummaryCalculate event to provide a custom summary and the GridView.PopupMenuShowingevent to add a corresponding item to the grid's footer menu.
See also:
Custom Aggregate Functions
Question Comments
Added By: Sir Kevin Heathfield at: 7/23/2013 3:49:25 AM
Not a single code comment.. Nice..
Added By: Matteo Lazzari at: 6/5/2014 3:12:58 AMWhy do you do:
foreach (DevExpress.Utils.Menu.DXMenuItem item in footerMenu.Items)
item.Enabled = true;
I see this is necessary for enable the menu items... But I would like to maintain disabled the summarization items not available for a particular field type (for example, the sum for the strings). Is this possible?
Thank you.
Hello,
Our grid inner logic disables all items in the summary popup menu when a custom summary is applied to the grid. We use this loop to overcome this behavior without creating a big hierarchy of derived controls.
If you need to disable some items, you can create a structure that stores items that should be disabled not to enable these items in this loop.
I hope this helps.
Ok, thank you. Using a dictionary that stores the key "FieldName + the summary Caption" and the value of the enabled property I can maintain the original enabled property value, except for the "None" element that I test in this way:
If item.Tag.Equals(GridStringId.MenuFooterNone) Then ...
Now, I've got another issue. Since my grid is inside the XAF Framework the active summarization items are stored in the user model and when I load the grid they are already visible. But the CustomSummaryCalculate logic fails because the tag has not value.
What can I do?
Hello,
Identification of a custom summary by tag is applicable for XAF, since it does not restore the SummaryItem.Tag property. If you have only one custom summary, you can simply remove a check of the CustomSummaryCalculate event handler.
If you have a number of summaries, you need to save the currently applied summary name and restore it manually when necessary.
I hope this helps.
Thank you Nikita. How can I save the currently applied summary name and how to restore it?
Added By: Nikita (DevExpress Support) at: 11/19/2014 7:16:30 AMHello,
You can serialize the currently applied property in any manner that is convenient in the View.ModelSaved event handler and restore these settings in the View.ModelLoaded event handler.
I hope this helps.
Hello Simon,
Our samples are zip files. So you can change the file resolution to zip and unpack the files. Please note that in this case you have to run the Project Converter against this project to make it work.