Hi,
Is it possible to put the selectcolumn or check box into the Group Header?
When the check box in the group header is selected, I will like all the select columns(checkboxes) ticked of the items within the groups.
and when any item in the group is unchecked, I would like the check box in group header is unchecked as well.
When the group has subgroups, I also want the subgroup checkbox to be checked when I loop through them using group.subgroups.
In the case, how could I grad a reference to the checkbox in the subgroup row?
Am I using the right approch with the code below?
Thanks,
Yu
Is it possible to put the selectcolumn or check box into the Group Header?
When the check box in the group header is selected, I will like all the select columns(checkboxes) ticked of the items within the groups.
and when any item in the group is unchecked, I would like the check box in group header is unchecked as well.
When the group has subgroups, I also want the subgroup checkbox to be checked when I loop through them using group.subgroups.
In the case, how could I grad a reference to the checkbox in the subgroup row?
Am I using the right approch with the code below?
<
telerik:RadGridView.GroupHeaderTemplate
>
<
DataTemplate
>
<
StackPanel
Orientation
=
"Horizontal"
>
<
CheckBox
Click
=
"RadGridViewGroupRowClicked"
Margin
=
"0 0 3 0"
/>
<
TextBlock
Text
=
"{Binding Group.Key}"
/>
</
StackPanel
>
</
DataTemplate
>
</
telerik:RadGridView.GroupHeaderTemplate
>
private
void
RadGridViewGroupRowClicked(
object
sender, System.Windows.RoutedEventArgs e)
{
var groupViewModel = (sender
as
CheckBox).DataContext
as
GroupViewModel;
var isChecked = (
bool
) (sender
as
CheckBox).IsChecked;
CheckUncheckRows(isChecked, groupViewModel);
}
public
void
CheckUncheckRows(
bool
isChecked, GroupViewModel groupViewModel)
{
CheckUncheckItems(isChecked, groupViewModel.Group);
}
public
void
CheckUncheckItems(
bool
isChecked, IGroup group)
{
if
(group.HasSubgroups)
{
foreach
(var subgroup
in
group.Subgroups)
{
CheckUncheckItems(isChecked, subgroup);
}
}
else
{
foreach
(var item
in
group.Items)
{
if
(isChecked)
{
baseToTargetGridView.SelectedItems.Add(item);
}
else
{
baseToTargetGridView.SelectedItems.Remove(item);
}
}
}
}
Thanks,
Yu