4 Answers, 1 is accepted
Generally the Aggregate Function is applied to all the items in the GridView.
Regarding your question, it would be better to implement your own logic for calculating the column footer based on the selection changed. You may subscribe for the SelectionChanged event handler and place your logic there.
Is this solution good for your case?
Didie
the Telerik team
Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

the problem is, that i am using MVVM here. All my logic is in the ViewModel and i would like to avoid the Selected Event in this case.
At first i tried to bind the IsSelected property from the Row to my ViewModel to get all selected items, but this did not work correctly (i think because of virtualization). Is this right or missed i something? This is my favoured approach, i would be very grateful if you can give me a solution for this approach.
<
telerik:RadGridView.RowStyle
>
<
Style
TargetType
=
"telerik:GridViewRow"
>
<
Setter
Property
=
"IsSelected"
Value="{Binding
Path
=
IsSelected
,
Mode
=
TwoWay
,
UpdateSourceTrigger
=
PropertyChanged
}"/>
</
Style
>
</
telerik:RadGridView.RowStyle
>
If i decide to use the Selected Event in the view how can i easily implement this aggregation? Currently my footer look like this:
<
telerik:GridViewDataColumn.Footer
>
<
StackPanel
TextElement.FontStyle
=
"Italic"
>
<
StackPanel
Orientation
=
"Horizontal"
>
<
Label
Content
=
"Avg:"
/>
<
Label
Margin
=
"5,0,0,0"
Content="{Binding
Path
=
DataContext
.OriginalAverage, RelativeSource={RelativeSource
Mode
=
FindAncestor
,
AncestorType
=
telerik
:RadGridView}}"></
Label
>
</
StackPanel
>
<
StackPanel
Orientation
=
"Horizontal"
>
<
Label
Content
=
"Sum:"
/>
<
Label
Margin
=
"5,0,0,0"
Content="{Binding
Path
=
DataContext
.OriginalSum, RelativeSource={RelativeSource
Mode
=
FindAncestor
,
AncestorType
=
telerik
:RadGridView}}"></
Label
>
</
StackPanel
>
</
StackPanel
>
</
telerik:GridViewDataColumn.Footer
>
In case you do want to avoid using events, then you may use a Behavior. You will need to add a SelectedItems property to your ViewModel, which you associate to the SelectedItems of the GridView through the Behavior.
The code in the ViewModel would be like:
private
ObservableCollection<
object
> selectedItems;
public
ObservableCollection<
object
> SelectedItems
{
get
{
return
selectedItems; }
set
{
selectedItems = value;
selectedItems.CollectionChanged +=
new
System.Collections.Specialized.NotifyCollectionChangedEventHandler(selectedItems_CollectionChanged);
}
}
void
selectedItems_CollectionChanged(
object
sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
//Update aggregate results.
if
(SelectedItems.Count != 0)
{
Sum = SelectedItems.OfType<Player>().Select(c => c.Number).Sum();
Average = SelectedItems.OfType<Player>().Select(c => c.Number).Average();
}
else
{
Sum = 0;
Average = 0;
}
}
I am attaching a sample project illustrating this approach.
Regards,
Didie
the Telerik team
Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!
