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

How to set DataTemplate of HierarchyChildTemplate (Code)

2 Answers 227 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jerome
Top achievements
Rank 1
Jerome asked on 26 Apr 2013, 03:00 PM
Hello,

I was trying to build up the DataTemplate for the HierarchyChildTemplate in my code.

As example the one from the online documentation http://www.telerik.com/help/wpf/gridview-how-to-access-child-gridview.html
<telerik:RadGridView Name="gridView" ItemsSource="{Binding Person}">
<telerik:RadGridView.ChildTableDefinitions>
<telerik:GridViewTableDefinition />
</telerik:RadGridView.ChildTableDefinitions>
<telerik:RadGridView.HierarchyChildTemplate>
<DataTemplate>
<telerik:RadGridView ItemsSource="{Binding Children}" Name="childGrid" ShowGroupPanel="False" />
</DataTemplate>
</telerik:RadGridView.HierarchyChildTemplate>
</telerik:RadGridView>

I tried something like:
gridView.HierarchyChildTemplate =
                new DataTemplate(
                        new RadGridView
                        {
                            ShowGroupPanel = false,
                            IsReadOnly = true,
                            ItemsSource = new Binding("Children")
                        });

But i set the dataType in that constructor and not same property like in the xaml. What's the property i need to set?

Thanks.


2 Answers, 1 is accepted

Sort by
0
Accepted
Dimitrina
Telerik team
answered on 29 Apr 2013, 11:19 AM
Hello,

This is not the correct syntax for creating the DataTemplate in code behiond. I would suggest you to declare it in XAML and then set it in code instead. 
For example:

this.gridView.TableDefinition.ChildTableDefinitions.Add(new GridViewTableDefinition());
this.gridView.HierarchyChildTemplate = this.FindResource("hierachyDataTemplate1") as DataTemplate;

Can you apply this?

Regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Jerome
Top achievements
Rank 1
answered on 29 Apr 2013, 11:44 AM
I was able to solve it with subscribing to the DataLoading event and use the GridViewDataControl instead of a second RadGridView.
Tags
GridView
Asked by
Jerome
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Jerome
Top achievements
Rank 1
Share this question
or