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

Access to hierarchical grids

5 Answers 96 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 16 Jul 2010, 06:13 AM
Hello guys.
I''ve got common hierarchical design grids;
<telerikGridView:RadGridView  Grid.Row="1" HorizontalAlignment="Left" x:Name="grRegistrateProducts"/>
            <telerikGridView:RadGridView.ChildTableDefinitions>              
                <telerikGridView:GridViewTableDefinition>
                    <telerikGridView:GridViewTableDefinition.Relation>
                        <telerikData:PropertyRelation ParentPropertyName="WorkPlaces" />
                    </telerikGridView:GridViewTableDefinition.Relation>
                </telerikGridView:GridViewTableDefinition>                   
            </telerikGridView:RadGridView.ChildTableDefinitions>           
            <telerikGridView:RadGridView.HierarchyChildTemplate>
                <DataTemplate>
                    <telerikGridView:RadGridView ItemsSource="{Binding WorkPlaces}" x:Name="grWorkPlaces" ShowGroupPanel="False" AutoGenerateColumns="False">
                        <telerikGridView:RadGridView.Columns>
                            <telerikGridView:GridViewDataColumn UniqueName="Id" IsReadOnly="True" MinWidth="200" MaxWidth="400"/>
                        </telerikGridView:RadGridView.Columns>
                    </telerikGridView:RadGridView>
                </DataTemplate>
            </telerikGridView:RadGridView.HierarchyChildTemplate>
            <telerikGridView:RadGridView.Columns>
                <telerikGridView:GridViewDataColumn UniqueName="Name" IsReadOnly="True" MinWidth="200" MaxWidth="400"/>
            </telerikGridView:RadGridView.Columns>
 </telerikGridView:RadGridView>
I need acces to inrenalGrid.CurrentItem. But at code I can't access to my grWorkPlaces. So what's wrong? And what should I do?
Thanks.

5 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 16 Jul 2010, 07:31 AM
Hi Andrew,

You can access the child grid with the help of the extension method ChildrenOfType<>. For example:

var selectedRow = (GridViewRow)this.clubsGrid.ItemContainerGenerator.ContainerFromItem(this.clubsGrid.SelectedItem);
var childGrid = selectedRow.ChildrenOfType<GridViewDataControl>().FirstOrDefault();
if (childGrid != null)
   {               
    Player currentPlayer = childGrid.CurrentItem as Player;
   }

You can find more information about the extension methods ChildrenOfType<> and ParentOfType<> in this blog post.

Regards,
Maya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Muhammad
Top achievements
Rank 1
answered on 20 Apr 2012, 12:53 PM
Hi Maya(Admin),
i got a query ,i have collection of objects which are not hierarchical but i want to display them in hierarchical grid.can you please tell me how i can set the hierarchical (inner nested grid) itemssource from the source code(dynamically)
with regards
0
Rossen Hristov
Telerik team
answered on 20 Apr 2012, 02:13 PM
Hello,

You can use the Row Details feature for that purpose and set the ItemsSource of your child grid (that is inside the row details template) to anything that you want in the LoadingRowDetails event handler.

Regards,
Ross
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Dave Navarro
Top achievements
Rank 2
answered on 28 May 2012, 11:16 PM
Hello,

I also have a child grid and I need to add a double click event to it.

With my parent grids I'd do it like this;
this.radGVRecords.AddHandler(GridViewCellBase.CellDoubleClickEvent, new EventHandler<RadRoutedEventArgs>(OnCellDoubleClick), true);

I usually place this code after my "InitializeComponent(); " line of code but I'm not sure now to achieve the same results with a child grid.

Please let me know and thanks!

~ Dave
0
Vlad
Telerik team
answered on 29 May 2012, 06:21 AM
Hi,

 To get reference to your child grid instance you can for example declare it using HierarchyChildTemplate and use Loaded event of the child grid itself. 

Regards,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
Andrew
Top achievements
Rank 1
Answers by
Maya
Telerik team
Muhammad
Top achievements
Rank 1
Rossen Hristov
Telerik team
Dave Navarro
Top achievements
Rank 2
Vlad
Telerik team
Share this question
or