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

Aggregate functions problem

5 Answers 212 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Yura
Top achievements
Rank 1
Yura asked on 21 Nov 2013, 10:53 AM
Hello!

I'm using RadDataGridView. I expect, that when data is changed
(i'm using INotify, so that with PropertyChanged event is all ok), aggregate functions have to be recalculated. But this don't happening without additional moves.
On forums there are a lot of advices to use Grid.CalculateAggregate, no matter that it is not good for MVVM. But this function doesn't recalculate anything.
So i tested a lot of variants and i found one, that works how expected, but i think this solve is too complex for this problem.
After data changed i use this code
//Refreshing aggregate functions
            var items = MyGrid.Items;
            foreach (var item in items)
            {
                items.EditItem(item);
                items.CommitEdit();
            }

So my question is: can i recalculate aggregate functions more easily?
More over, attached code works only when i am grouping my collection only by Second property - this is huge problem too.
Here is the simple project which resolve the problem.

5 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 25 Nov 2013, 04:02 PM
Hi,

In order to get the group aggregates refreshed, a CollectionChanged event of the bound collection should be raised. One option to do so is the way you do it. This is also explained in this help article.

Another solution would be to Reset the GroupDescriptors collection (RadGridView.GroupDescriptors.Reset()).

Regards,
Didie
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Yura
Top achievements
Rank 1
answered on 26 Nov 2013, 08:58 AM
Hi,

RadGridView.GroupDescriptors.Reset() function reseting scroll, so it is not best solution if there is scroll on grid. My solution (and yours) is not good enough too, because if i want update all items on grid (to update all aggregate functions) i need to use loop ("foreach", "for" etc) but collection may be changed at this time. This leading to exception.

Is any another solution of this problem?

Thanks.



0
Dimitrina
Telerik team
answered on 26 Nov 2013, 05:12 PM
Hi,

Another option would be to try invoking a Rebind() of the entire RadGridView.

Regards,
Didie
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Yura
Top achievements
Rank 1
answered on 28 Nov 2013, 09:47 AM
Hi,

Rebind() function also resets the scroll. How can i safely recalculate aggregate functions without reseting the scroll?

Thanks.
0
Dimitrina
Telerik team
answered on 28 Nov 2013, 09:56 AM
Hi,

The ScrollBar is Reset as the Rebind() causes the entire view (with all the rows) to be recreated. A CollectionChanged event with action Reset is raised in that case.

I would suggest you to invoke a RadGridView.GroupDescriptors.Reset() to reset all the group rows or raise a CollectionChanged on a single item, not the entire view (see this help article), to re calculate the value of a single group.

Regards,
Didie
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
GridView
Asked by
Yura
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Yura
Top achievements
Rank 1
Share this question
or