SelectColumn in Group Header

7 posts, 0 answers
  1. Yu
    Yu avatar
    17 posts
    Member since:
    Jul 2012

    Posted 18 Feb 2013 Link to this post

    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
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 19 Feb 2013 Link to this post

    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.

  3. Inger Marie
    Inger Marie avatar
    86 posts
    Member since:
    Nov 2010

    Posted 08 Jul 2014 in reply to Dimitrina Link to this post

    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?
  4. Inger Marie
    Inger Marie avatar
    86 posts
    Member since:
    Nov 2010

    Posted 08 Jul 2014 in reply to Inger Marie Link to this post

    Never mind. I found out that Grouping does get fired when ungrouping.
    I will try to remove the memory leak using that information.
  5. Heiko
    Heiko avatar
    153 posts
    Member since:
    Oct 2012

    Posted 24 Oct 2014 in reply to Inger Marie Link to this post

    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!
  6. Yordanka
    Admin
    Yordanka avatar
    634 posts

    Posted 24 Oct 2014 Link to this post

    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.

     
  7. Inger Marie
    Inger Marie avatar
    86 posts
    Member since:
    Nov 2010

    Posted 27 Oct 2014 in reply to Heiko Link to this post

    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...)

Back to Top