I currently have a RadGridView that is bound to a collection of objects. One of those objects contains a property that is calculated based on a user-supplied value, so whenever the user changes the value, the value in every row changes as well.
I am able to manually update the Footer Aggregate using .CalculateAggregates(), however if the Grid is grouped, this does not update the aggregates that are located in the group totals.
How can I make the RadGridView re-calculate the aggregates in the grouped records? The relevant bits of code are below
I am able to manually update the Footer Aggregate using .CalculateAggregates(), however if the Grid is grouped, this does not update the aggregates that are located in the group totals.
How can I make the RadGridView re-calculate the aggregates in the grouped records? The relevant bits of code are below
<TextBox Text="{Binding SalePercent}" />
<telerik:RadGridView x:Name="MyGrid" DataContextChanged="MyGrid_DataContextChanged" ItemsSource="{Binding MyObservableCollection}" ShowColumnFooters="True"> <telerik:RadGridView.Columns> <telerik:GridViewDataColumn DataMemberBinding="{Binding Price, StringFormat=N2}" Header="Price"> <telerik:GridViewDataColumn.AggregateFunctions> <telerik:SumFunction Caption="Price: " ResultFormatString="{}{0:C}" /> </telerik:GridViewDataColumn.AggregateFunctions> </telerik:GridViewDataColumn> <telerik:GridViewDataColumn DataMemberBinding="{Binding SalePrice, StringFormat=N2}" Header="Sale Price"> <telerik:GridViewDataColumn.AggregateFunctions> <telerik:SumFunction Caption="Sale Price: " ResultFormatString="{}{0:C}" /> </telerik:GridViewDataColumn.AggregateFunctions> </telerik:GridViewDataColumn> </telerik:RadGridView.Columns></telerik:RadGridView>
private void MyGrid_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e){ MyViewModel vm = MyGrid.DataContext as MyViewModel; if (vm != null) vm.PropertyChanged += MyViewModel_PropertyChanged; MyGrid.DataContextChanged -= MyGrid_DataContextChanged;}void MyViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e){ if (e.PropertyName == "SalePercent") MyGrid.CalculateAggregates();}
void MyViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case "SalePercent":
foreach (var item in MyObservableCollection)
item.SalePrice = item.Price * SalePercent;
break;
}
}
