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

Error when combining HierarchyChildTemplate and Self-Referencing GridView

4 Answers 82 Views
GridView
This is a migrated thread and some comments may be shown as answers.
M
Top achievements
Rank 1
M asked on 15 Mar 2012, 09:38 AM
Hello,

i've got a problem with a self referencing hierarchy in a gridview.
I've got a List1 that i want to display in a gridview. List 1 has a Property List2 which contains elements of class2 --> (List<class2>).
For this case i used the HierarchyChildTemplate and it works fine.
my problem is that my List2 structure looks like this

id  parentId  name
1                   a
2       1          b
3       1          c
4       2          d
5       4          e

it is an n-level self referencing hierarchy. so i decided to do it similar to this example:
http://www.telerik.com/help/wpf/gridview-self-referencing-grid.html

myproblem is that the first 2 levels (handled by the HierarchyChildTemplate ) are working fine and the 3 to n level Elements (handled by the self referencing hierarchy example) are not displayed in the grid



Code:


<telerik:RadGridView x:Name="RadTreeListView1"
                AutoGenerateColumns="False" IsReadOnly="True" ItemsSource="{Binding List1, Mode=TwoWay}"
                                 CanUserResizeColumns="True" CanUserFreezeColumns="False"
                                 RowLoaded="RadTreeListView1_RowLoaded">
            <telerik:RadGridView.ChildTableDefinitions>
                <telerik:GridViewTableDefinition />
            </telerik:RadGridView.ChildTableDefinitions>
            <telerik:RadGridView.Columns>
                 <telerik:GridViewDataColumn
 
                        ...some Columndefinitions            />
            </telerik:RadGridView.Columns>
            <telerik:RadGridView.HierarchyChildTemplate>
                <DataTemplate>
                    <telerik:RadGridView x:Name="StrukturListe" IsFilteringAllowed="False"
                                         CanUserSortColumns="False"
                                         CanUserFreezeColumns="False"
                                         AutoGenerateColumns="False" 
                                         ItemsSource="{Binding List2,Mode=TwoWay}">
                        <telerik:RadGridView.ChildTableDefinitions>
                            <telerik:GridViewTableDefinition>
                                <telerik:GridViewTableDefinition.Relation>
                                    <telerik:TableRelation IsSelfReference="True">
                                        <telerik:TableRelation.FieldNames>
                                            <telerik:FieldDescriptorNamePair
                                                ParentFieldDescriptorName="Id"
                                                ChildFieldDescriptorName="ParentId"/>
                                        </telerik:TableRelation.FieldNames>
                                    </telerik:TableRelation>
                                </telerik:GridViewTableDefinition.Relation>
                            </telerik:GridViewTableDefinition>
                        </telerik:RadGridView.ChildTableDefinitions>
                        <telerik:RadGridView.Columns>
                            <telerik:GridViewDataColumn
 
                        ...some Columndefinitions            />
 
                        </telerik:RadGridView.Columns>
                    </telerik:RadGridView>
                </DataTemplate>
            </telerik:RadGridView.HierarchyChildTemplate>
        </telerik:RadGridView>


myClasshierarchy lools like this:

class1
    prop a
    prop b
    List<class2>    <-- 1 level deep

class2
    prop 1
    prop 2
    int ID
    int Parent

4 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 15 Mar 2012, 11:07 AM
Hi,

 Indeed HierarchyChildTemplate will break the chain of the grid automatic self-reference hierarchy. You can use the approach from this demo to set various properties for the auto-generated child grids. 

Greetings,
Vlad
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
M
Top achievements
Rank 1
answered on 15 Mar 2012, 12:25 PM
Hi Vlad,

thank you for your reply. In your demo there is just one self referencing list and it just displays different member.
In my case the problem is that i need the HierarchyChildTemplate because the first to second level of my relation is not self referencing. Only the 2nd to n levels are self referencing.

so i dont know if this is possible with your demo?!
0
Dinesh
Top achievements
Rank 1
answered on 15 Mar 2019, 05:11 AM

Add an expand All or collapse all button to the parent header

 I have a basic HierarchyChildTemplate grid with parent and hild relation ship defined and the grid works fine. One of the requirements it to add a plus button in the header for the first column when clicked by the user it has to expand all the rows with row details  and collpase when clicked again just like it would behave for each row. 

I was able to add a button and expand the rows details successfully  but I need the button to show up in the row header.

Any help in this regards is appreciated 

Thank you 

0
Dilyan Traykov
Telerik team
answered on 19 Mar 2019, 02:04 PM
Hello Dinesh,

I just replied to the other thread which you opened. For completeness, I'm also pasting my reply here:

"The desired result can be achieved by adding a GridViewToggleButton to the PART_HierarchyIndentPresenter element of the GridViewHeaderRow template. Please have a look at the following article for details on how to extract and modify the control template of a control.

You can then handle the Checked and Unchecked events of the button, possibly by defining an attached behavior for it and call the ExpandAllHierarchyItems and CollapseAllHierarchyItems methods respectively.

For your convenience, I've also attached a sample project demonstrating this approach."

Please have a look and let me know whether a similar approach would be applicable at your end. Should any further questions or concerns arise, may I kindly ask you to continue the conversation in only one of the two threads so that we can avoid duplicate content? Thank you in advance for your cooperation on the matter.

Regards,
Dilyan Traykov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
GridView
Asked by
M
Top achievements
Rank 1
Answers by
Vlad
Telerik team
M
Top achievements
Rank 1
Dinesh
Top achievements
Rank 1
Dilyan Traykov
Telerik team
Share this question
or