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

Grouped Event - no GroupHeaderRows

4 Answers 121 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Heiko
Top achievements
Rank 1
Iron
Veteran
Heiko asked on 24 Oct 2014, 03:55 PM
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

4 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 27 Oct 2014, 02:37 PM
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.

 
0
Heiko
Top achievements
Rank 1
Iron
Veteran
answered on 28 Oct 2014, 08:08 AM
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
0
Dimitrina
Telerik team
answered on 29 Oct 2014, 09:43 AM
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.

 
0
Heiko
Top achievements
Rank 1
Iron
Veteran
answered on 30 Oct 2014, 08:12 AM
Thanks, that was a great help!
Tags
GridView
Asked by
Heiko
Top achievements
Rank 1
Iron
Veteran
Answers by
Dimitrina
Telerik team
Heiko
Top achievements
Rank 1
Iron
Veteran
Share this question
or