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

SelectColumn in Group Header

6 Answers 353 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Yu
Top achievements
Rank 1
Yu asked on 18 Feb 2013, 04:57 PM
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?

<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

6 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 19 Feb 2013, 09:17 AM
Hi Yu,

I have attached a sample project showing how you could select the rows under the group using a CheckBox in the GroupHeaderRow.

I hope it is helpful.
 

Kind regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Inger Marie
Top achievements
Rank 1
answered on 08 Jul 2014, 09:42 AM
I know this is an old post, but it was the best I could find regarding group selection in radgridview.

I think the sample project has a serious memory leak (my users will group, ungroup and group again.. and again)..

This code:
 grid.SelectionChanged += behavior.RadGridViewSelectionChanged;
gets called each time a new group is created, but the event is never unhooked when the group is removed.

I have not been able to identify the right spot to call
 grid.SelectionChanged -= behavior.RadGridViewSelectionChanged;

Seems like events are being raised when the grid is grouped, but not when it is ungrouped?
0
Inger Marie
Top achievements
Rank 1
answered on 08 Jul 2014, 11:06 AM
Never mind. I found out that Grouping does get fired when ungrouping.
I will try to remove the memory leak using that information.
0
Heiko
Top achievements
Rank 1
answered on 24 Oct 2014, 07:42 AM
Did you manage to remove the memory leak? Would be nice if you post your solution here because this is exactly what I need in my project right now...

Thanks!
0
Yordanka
Telerik team
answered on 24 Oct 2014, 08:52 AM
Hi Neils,

We will consider updating the SDK demo. As the behavior used in the project is completely custom you can extend it. In order to avoid the problem you should assure the event handlers have been detached.

Regards,
Yordanka
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Inger Marie
Top achievements
Rank 1
answered on 27 Oct 2014, 08:30 AM
No, I did not find a solution to this problem.
What I did was to implement a new shortcut (<ctrl>-<g>) that works when you have selected 1 item in a group. Ctrl-g will select them all.

I am not completely sastisfied with this solution because my users are computer no-obs and many of them are new to my program. Having hidden functionality like this is not good (I did put some text on the screen to tell the users what to do, but it's still a secondary quality solution...)

Tags
GridView
Asked by
Yu
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Inger Marie
Top achievements
Rank 1
Heiko
Top achievements
Rank 1
Yordanka
Telerik team
Share this question
or