Grouped Event - no GroupHeaderRows

5 posts, 0 answers
  1. Heiko
    Heiko avatar
    153 posts
    Member since:
    Oct 2012

    Posted 24 Oct 2014 Link to this post

    I am working on a Behavior to extend the GridView with CheckBoxes inside the group headers. To achieve this I created a System.Windows.Interactivity.Behavior where in the "Loaded" event of the GridView I add Eventhandlers to all Checkboxes in the group headers. To get a list of all GroupHeaderRow items I use the following code:

    var groupHeaderRows =
        AssociatedObject.ChildrenOfType<GroupHeaderRow>().ToList();

    This is working as expected, I get all group headers and can work with them. (Note: the "AssociatedObject" is the GridView to which the Behavior is attached to; the GroupRenderMode is "Flat".)

    When a user changes the grouping be dragging/dropping a column to/from the group panel the "Grouped" event occurs. Unfortunately the list of GroupHeaderRow items is empty right after this event occurs and using the code above. On the other side I tried to respond to the "GroupDescriptors.CollectionChanged" event, but the list of GroupHeaderRows has not been refreshed which means I get the GroupHeaderRows of the old grouping before the collection was changed.
    Now I am stuck. How can I get the list of all current GroupHeaderRow items after the user changed the grouping via UI?

    Second question: how can I get the GroupHeaderRow that a selected item belongs to when I respond to the "SelectionChanged" event of the GridView?

    TIA
    Neils
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 27 Oct 2014 Link to this post

    Hi Neils,

    Once I configured the Flat mode, I was able to access all the GroupHeaderRows when clicking on a button after grouping is performed. If you try to access them when the Grouped event is raised, then they are still not available.

    As to your second question, you can access the parent group of the selected item as follows:
    private void clubsGrid_SelectionChanged(object sender, SelectionChangeEventArgs e)
     {
         var item = e.AddedItems[0];
         foreach (QueryableCollectionViewGroup group in clubsGrid.Items.Groups)
         {
             if (group.Items.Contains(item))
             {
                 MessageBox.Show(string.Format("The parent group is: {0}", group.Key));
                 break;
             }
         }
     }
    }

    Regards,
    Dimitrina
    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.

     
  3. Heiko
    Heiko avatar
    153 posts
    Member since:
    Oct 2012

    Posted 28 Oct 2014 in reply to Dimitrina Link to this post

    Hi Dimitrina,

    thanks for your reply. For my second question: I found out that there is a method called "FindGroupByItem" in GridViewDataControlExtensions library.
    For my first question: of course I can access all GroupHeaderRows when clicking a button; this is what I do when the control is loaded. The problem is: I need to access the GroupHeaderRows when the grouping has been changed by the user (normally: the Grouped event). Which event should I use?

    Regards
    Neils
  4. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 29 Oct 2014 Link to this post

    Hi Neils,

    This is indeed correct. Thank you for pointing this option out. As to your second question, you cannot access the still non existing group rows in the Grouped event. You could subscribe for the first LayoutUpdated after it instead when they will be available.
    For example:
         private void clubsGrid_Grouped(object sender, GridViewGroupedEventArgs e)
         {
             this.clubsGrid.LayoutUpdated += clubsGrid_LayoutUpdated;
         }
         private void clubsGrid_LayoutUpdated(object sender, EventArgs e)
         {
             var groupHeaderRows =
    clubsGrid.ChildrenOfType<GroupHeaderRow>().ToList();
             Debug.WriteLine("Grouped: " + groupHeaderRows.Count);
             this.clubsGrid.LayoutUpdated -= clubsGrid_LayoutUpdated;
         }

    I hope this helps.

    Regards,
    Dimitrina
    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.

     
  5. Heiko
    Heiko avatar
    153 posts
    Member since:
    Oct 2012

    Posted 30 Oct 2014 in reply to Dimitrina Link to this post

    Thanks, that was a great help!
Back to Top