Hi,
I have bound the GridView to an collection of business-objects that have a IsSelected-Property(bool) and an according CheckBox-Column.
To be able to change this property for all objects in a group I came up with this:
1. This checks and unchecks all items in the group and subgroups but I do not know how to get to the GridViewGroupRow of the subgroups and also (un)check their CheckBoxes. I can get the Group from GridViewGroupRow but when walking down the subgroups I do not know how to get their GridViewGroupRows.
2. I also wasn't able to get the PropertyName from the Group - the Group's Key-Property is the actual property's value. How to get the property's name to know what property is grouped by this Group?
3. And it would be very nice if (un)checking items would be reflected in the parent-group-checkbox(es).
Any suggestion is welcome.
Best Regards
Steffen
I have bound the GridView to an collection of business-objects that have a IsSelected-Property(bool) and an according CheckBox-Column.
To be able to change this property for all objects in a group I came up with this:
<Style x:Key="CustomRowStyle" TargetType="telerik:GridViewGroupRow"> |
<EventSetter Event="Loaded" Handler="GridViewGroupRow_Loaded" /> |
</Style> |
private void GridViewGroupRow_Loaded(object sender, RoutedEventArgs args) |
{ |
GridViewGroupRow groupRow = (GridViewGroupRow)args.OriginalSource; |
CheckBox cb = new CheckBox() { Content = groupRow.Group.Key }; |
cb.Tag = groupRow; |
cb.Checked += new RoutedEventHandler(groupRow_CheckChanged); |
cb.Unchecked += new RoutedEventHandler(groupRow_CheckChanged); |
groupRow.Header = cb; |
} |
void groupRow_CheckChanged(object sender, RoutedEventArgs e) |
{ |
GridViewGroupRow groupRow = (sender as CheckBox).Tag as GridViewGroupRow; |
recursiveGroupSelection(groupRow.Group, (sender as CheckBox).IsChecked ?? false); |
} |
private void recursiveGroupSelection(IGroup g, bool check) |
{ |
foreach (var item in g.Items)//select items in this group |
{ |
if (item is BusinessObject) |
{ |
(item as BusinessObject).IsSelected = check; |
} |
} |
//the same for all subgroups |
foreach (Group sub in g.Subgroups) |
{ |
recursiveGroupStationSelection(sub, check); |
} |
} |
2. I also wasn't able to get the PropertyName from the Group - the Group's Key-Property is the actual property's value. How to get the property's name to know what property is grouped by this Group?
3. And it would be very nice if (un)checking items would be reflected in the parent-group-checkbox(es).
Any suggestion is welcome.
Best Regards
Steffen