This is a migrated thread and some comments may be shown as answers.

Problem with grouping and aggregate functions.

3 Answers 89 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Evgeny
Top achievements
Rank 1
Evgeny asked on 06 Mar 2012, 07:21 AM
Hello. I have such problem: when I try to add aggregate functions for group, that was created from user interface(user drags column headers to grouping panel), i cant use foreach for groups collection, that have more than one element. I get exception, that talk my group collection has changed. But i changed only aggregate functions collection. Code demonstrated such behaviour is below:

foreach (var group in AssociatedObject.GroupDescriptors)
{
    var localGroup = (group as GroupDescriptor);
 
    AggregateFunctionCollection aggregateFunctions = localGroup == null ?
        (@group as ColumnGroupDescriptor).Column.AggregateFunctions :
           localGroup.AggregateFunctions;
 
   aggregateFunctions.Clear();
 
    aggregateFunctions.Add(new CountFunction { Caption = GroupAggregatesName });
}

What is the way to solve this problem? Please help.

3 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 06 Mar 2012, 08:10 AM
Hi,

When you group using drag & drop the grid will add ColumnGroupDescriptor. You can use for example:

foreach (var group in AssociatedObject.GroupDescriptors.OfType<ColumnGroupDescriptor>())

Regards,
Vlad
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Evgeny
Top achievements
Rank 1
answered on 06 Mar 2012, 08:25 AM
It's right. But I have in my collection GroupDescriptor and ColumnGroupDescriptor, because I use grouping at the start of my application. And it always make exception, when collection contain different type descriptors.
0
Evgeny
Top achievements
Rank 1
answered on 11 Mar 2012, 10:24 AM
I found it doesn't work if there are more than one ColumnGroupDescription in GroupDescriptors collection. Always throw exception, thatGroupDescriptors collection was changed after changing AggregateFunctions collection. I can't iterate groups in GroupDescriptors collection. So what is the right way to resolve this problem? 
Tags
GridView
Asked by
Evgeny
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Evgeny
Top achievements
Rank 1
Share this question
or