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

Accessing elements in HierarchyChildTempate?

4 Answers 123 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 21 Mar 2012, 11:14 PM
I have a RadGridView that displays summary data for a group of parent records.

On it I have a HierarchyChildTemplate, defining another RadGridView that displays summary data for a group of child records. In this inner grid, I have a RowDetailsTemplate that contains a RadDataForm that displays detailed data for the child records. The inner grid has RowDetailsVisibilityMode="VisibileWhenSelected".

What I want is to add a context menu that toggles RowDetailsVisibilityMode to "Collapsed".

I have a reference to the parent grid. What I can't figure out is how to get a reference to the child grids that are generated from the template.

4 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 22 Mar 2012, 08:02 AM
Hello,

Each of the child grids can be accessed through its corresponding row using the ChildrenOfType method. The code would look like so:

GridViewRow selectedRow = this.clubsGrid.ItemContainerGenerator.ContainerFromItem(this.clubsGrid.SelectedItem) as GridViewRow;
GridViewDataControl childGrid = selectedRow.ChildrenOfType<GridViewDataControl>().FirstOrDefault();

However, please note that if the child grid is not displayed (i.e. the corresponding row is not expanded), it will not be created and you will get a null value. Greetings,
Didie
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Jeff
Top achievements
Rank 1
answered on 22 Mar 2012, 04:00 PM
To clarify, I want to toggle RowDetailsVisibilityMode on all the rows, not just the current.

Using ContainerFromItem() and ChildrenOfType() on all the rows seems to work to toggle RowDetailsVisibilityMode on the rows that have been expanded (for whom ChildrenOfType() does not return null). But it doesn't seem to effect the rows that haven't yet been expanded.

My guess is I'm going to need to find the HierarchyChildTemplate, and toggle the flag there, as well.

=========== EDITED ===========

So, I was looking into what would be necessary to modify a DataTemplate in code, and not having much luck.  So then I was thinking about having two templates, with different RowDetailsVisibilityMode values.  And that bugged me.  So then I was thinking about creating a single template, making a copy, and then switching the one value, when I realized I'd been thinking about this all wrong.

So I created a DependencyProperty on the UserControl that wraps the parent grid, and bound the RowDetailsVisibilityMode properties of the child grids to it.  As child hierarchies are constructed from the template, their grids will all be bound to that same DependencyProperty. Which means that when I toggle the DependencyProperty between Collapsed and VisibleWhenSelected, it affects all the child rows, whether previously or not yet to be instantiated.
0
Accepted
Dimitrina
Telerik team
answered on 23 Mar 2012, 01:34 PM
Hello,

 Indeed you are right that you can find only the child inside the expanded rows (they have the child grid created).
From your Edit, I believe that you have resolved your problem. Could you please let me know in case you have problems binding to this DependencyProperty? 

Kind regards,
Didie
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Jeff
Top achievements
Rank 1
answered on 23 Mar 2012, 03:26 PM
Yes.  Binding to a dependency property in the template worked fine.
Tags
GridView
Asked by
Jeff
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Jeff
Top achievements
Rank 1
Share this question
or