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

More Hierarchy Level

2 Answers 79 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Orit
Top achievements
Rank 1
Orit asked on 24 Aug 2009, 11:40 AM
Hello
I want to have three levels of hierarchy
this is my xaml

<telerik:RadGridView  Name="gvAccount" Width="auto" ColumnsWidthMode="Fill" 
                              AutoGenerateColumns="False" FlowDirection="RightToLeft" ShowGroupPanel="False" IsFilteringAllowed="False" CanUserResizeColumns="False">  
                            <telerik:RadGridView.Columns> 
                            <telerik:GridViewDataColumn IsReadOnly="True" UniqueName="BudgetTypeName" Header="סוג תקציב"  Width="90"/>  
                            <telerik:GridViewDataColumn IsReadOnly="True" UniqueName="Number" Header="מספר חשבון" Width="90" /> 
                            <telerik:GridViewDataColumn IsReadOnly="True" UniqueName="Name" Header="שם חשבון"  Width="90"/>  
                            <telerik:GridViewDataColumn IsReadOnly="True" UniqueName="ActivityBudget" Header="הקצבה כוללת &#13;אש''ח"  Width="90"/>  
                            <telerik:GridViewDataColumn IsReadOnly="True" UniqueName="TotalBudget" Header="יתרה&#13;לתקצוב" Width="90" /> 
                            <telerik:GridViewDataColumn IsReadOnly="True" UniqueName="PlanBudget" Header="שריון&#13;לפעילות" Width="90"/>  
                            <telerik:GridViewDataColumn IsReadOnly="True" UniqueName="SumActualBudget" Header="התחיבות&#13;לפעילות" Width="90" /> 
                            <telerik:GridViewDataColumn IsReadOnly="True" UniqueName="a" Header="שולם&#13;בפועל"  Width="90"/>  
                            <telerik:GridViewDataColumn IsReadOnly="True" UniqueName="BudgetAllocation" Header="יתרה&#13;לתשלום" Width="90"/>  
                            <telerik:GridViewComboBoxColumn DataMemberBinding="{Binding Path=ActivityTypeName}"      
                                    DisplayMemberPath="Name" SelectedValueMemberPath="Name" Header="סוג&#13;פעילות" UniqueName="ActivityTypeName" Width="90*"/>  
                        </telerik:RadGridView.Columns> 
                        <telerik:RadGridView.HierarchyChildTemplate> 
                            <DataTemplate> 
                                <StackPanel DataContext="{x:Null}">  
                                    <telerik:RadGridView CanUserReorderColumns="False" Name="gvBudget" ColumnsWidthMode="Fill" 
                                             CanUserFreezeColumns="False" ShowGroupPanel="False" AutoGenerateColumns="False" ItemsSource="{Binding}" 
                                             Loaded="OnChildGridLoaded" FlowDirection="RightToLeft" IsFilteringAllowed="False" ShowColumnHeaders="False" ColumnBackground="AliceBlue" HorizontalContentAlignment="Right" ClipToBounds="True">  
                                        <telerik:RadGridView.Columns> 
                                                <telerik:GridViewDataColumn IsReadOnly="True" UniqueName="BudgetTypeName" Header="סוג תקציב"  Width="90"/>  
                                                <telerik:GridViewDataColumn IsReadOnly="True" UniqueName="Number" Header="מספר חשבון"  Width="90"/>  
                                                <telerik:GridViewDataColumn IsReadOnly="True" UniqueName="Name" Header="שם חשבון"  Width="90"/>  
                                                <telerik:GridViewDataColumn IsReadOnly="True" UniqueName="ActivityBudget" Header="הקצבה כוללת &#13;אש''ח"  Width="90"/>  
                                                <telerik:GridViewDataColumn IsReadOnly="True" UniqueName="TotalBudget" Header="יתרה&#13;לתקצוב"  Width="90"/>  
                                                <telerik:GridViewDataColumn IsReadOnly="True" UniqueName="PlanBudget" Header="שריון&#13;לפעילות" Width="90"/>  
                                                <telerik:GridViewDataColumn IsReadOnly="True" UniqueName="SumActualBudget" Header="התחיבות&#13;לפעילות"  Width="90"/>  
                                                <telerik:GridViewDataColumn IsReadOnly="True" UniqueName="a" Header="שולם&#13;בפועל"  Width="90"/>  
                                                <telerik:GridViewDataColumn IsReadOnly="True" UniqueName="BudgetAllocation" Header="יתרה&#13;לתשלום" Width="90"/>  
                                                <telerik:GridViewComboBoxColumn DataMemberBinding="{Binding Path=ActivityTypeName}"      
                                                    DisplayMemberPath="Name" SelectedValueMemberPath="Name" Header="סוג&#13;פעילות" UniqueName="ActivityTypeName"  Width="90*"/>  
                                        </telerik:RadGridView.Columns> 
                                        <telerik:RadGridView.HierarchyChildTemplate> 
                                            <DataTemplate> 
                                                <StackPanel DataContext="{x:Null}">  
                                                    <telerik:RadGridView CanUserReorderColumns="False" Name="gvSubBudget" ColumnsWidthMode="Fill" 
                                             CanUserFreezeColumns="False" ShowGroupPanel="False" AutoGenerateColumns="False" ItemsSource="{Binding}" 
                                             Loaded="OnSubChildGridLoaded" FlowDirection="RightToLeft" IsFilteringAllowed="False" ShowColumnHeaders="False" ColumnBackground="AliceBlue" HorizontalContentAlignment="Right" ClipToBounds="True">  
                                                        <telerik:RadGridView.Columns> 
                                                            <telerik:GridViewDataColumn IsReadOnly="True" UniqueName="BudgetTypeName" Header="סוג תקציב"  Width="90"/>  
                                                            <telerik:GridViewDataColumn IsReadOnly="True" UniqueName="Number" Header="מספר חשבון"  Width="90"/>  
                                                            <telerik:GridViewDataColumn IsReadOnly="True" UniqueName="Name" Header="שם חשבון"  Width="90"/>  
                                                            <telerik:GridViewDataColumn IsReadOnly="True" UniqueName="ActivityBudget" Header="הקצבה כוללת &#13;אש''ח"  Width="90"/>  
                                                            <telerik:GridViewDataColumn IsReadOnly="True" UniqueName="TotalBudget" Header="יתרה&#13;לתקצוב"  Width="90"/>  
                                                            <telerik:GridViewDataColumn IsReadOnly="True" UniqueName="PlanBudget" Header="שריון&#13;לפעילות" Width="90"/>  
                                                            <telerik:GridViewDataColumn IsReadOnly="True" UniqueName="SumActualBudget" Header="התחיבות&#13;לפעילות"  Width="90"/>  
                                                            <telerik:GridViewDataColumn IsReadOnly="True" UniqueName="a" Header="שולם&#13;בפועל"  Width="90"/>  
                                                            <telerik:GridViewDataColumn IsReadOnly="True" UniqueName="BudgetAllocation" Header="יתרה&#13;לתשלום" Width="90"/>  
                                                            <telerik:GridViewComboBoxColumn DataMemberBinding="{Binding Path=ActivityTypeName}"      
                                                    DisplayMemberPath="Name" SelectedValueMemberPath="Name" Header="סוג&#13;פעילות" UniqueName="ActivityTypeName"  Width="90*"/>  
                                                        </telerik:RadGridView.Columns> 
                                                    </telerik:RadGridView> 
                                                </StackPanel> 
                                            </DataTemplate> 
                                        </telerik:RadGridView.HierarchyChildTemplate> 
                                    </telerik:RadGridView> 
                                </StackPanel> 
                            </DataTemplate> 
                        </telerik:RadGridView.HierarchyChildTemplate>                       
                    </telerik:RadGridView> 

and this is my code

 private void BindDataMainGrid()  
        {  
            try  
            {  
                ((GridViewComboBoxColumn)this.gvAccount.Columns["ActivityTypeName"]).ItemsSource = ComboBoxValues.GetComboValues(CommonValues.GetActivityType());  
 
 
                DataSet dataSet = this.GetData();  
 
                // This is needed to make the grid use the HierarchyChildTemplate  
                GridViewTableDefinition detailDefinition = new GridViewTableDefinition();  
 
                // Tell the detailsDefinition to pull its data from the Details DataTable.  
                detailDefinition.DataSource = dataSet.Tables["Budget"].DefaultView;  
 
                // Specify the relation between the two tables, similar to what is done in the DataSet.  
                TableRelation tr = new TableRelation();  
                tr.FieldNames.Add(new FieldDescriptorNamePair("ID", "ParentID"));  
                detailDefinition.Relation = tr;  
 
                // Add a GridViewTableDefinition to the grid to make it use the HierarchyChildTemplate  
                // defined in XAML.  
                if (this.gvAccount.TableDefinition.ChildTableDefinitions.Count < 1)  
                    this.gvAccount.TableDefinition.ChildTableDefinitions.Add(detailDefinition);  
 
                // Bind the grid to the "master" table.  
                this.gvAccount.ItemsSource = dataSet.Tables["Account"].DefaultView;  

 private DataSet GetData()  
        {  
            try  
            {  
                dsBudget dsac = ServiceData.GetBudgetsByAccount(1);  
                if (dsac != null)  
                {  
                    DataSet ds = new DataSet();  
                    //DataTable dt = dsac.Tables["Budget"];  
                    DataView dv = new DataView(dsac.Tables["Budget"], "Type=1", "", DataViewRowState.CurrentRows);  
                    ds.Tables.Add((DataTable)dv.ToTable("Account"));  
                    dv = new DataView(dsac.Tables["Budget"], "Type=2", "", DataViewRowState.CurrentRows);  
                    ds.Tables.Add((DataTable)dv.ToTable("Budget"));  
                    dv = new DataView(dsac.Tables["Budget"], "Type=3", "", DataViewRowState.CurrentRows);  
                    ds.Tables.Add((DataTable)dv.ToTable("SubBudget"));  
 
                    ds.Relations.Add("BudgetRelation",  
                    ds.Tables["Account"].Columns["ID"],  
                    ds.Tables["Budget"].Columns["ParentID"]);  
 
                    ds.Relations.Add("SubBudgetRelation",  
                    ds.Tables["Budget"].Columns["ID"],  
                    ds.Tables["SubBudget"].Columns["ParentID"]);  
 
                    return ds;  
                }  
            }  
            catch   
            {   
                  
            }  
            return null;  
        }  
    } 

My question is
what code do I have to add
in order to see the second child level

Thanks

2 Answers, 1 is accepted

Sort by
0
Accepted
Rossen Hristov
Telerik team
answered on 27 Aug 2009, 12:09 PM
Hi Orit,

The <StackPanel DataContext="{x:Null}"> is a legacy hack that you need to remove. It was used in the past to overcome a shortcoming, but now everything should work without it in a more straightforward way.

Please, see my answer to the same question in this forum post. There is a sample project attached in the forum post that demonstrates how to do a 3-Level Hierarchy. It is for Silverlight, but the code-base is exactly the same so it should be the same in WPF. You will also have to get the latest version of our product.

Please, examine the source code that I have posted carefully and you will have 3-Level Hierarchy in no time. Let me know if you have any other questions.

Kind regards,
Ross
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Orit
Top achievements
Rank 1
answered on 02 Sep 2009, 07:01 AM
Thank you!
It works fine.

Tags
GridView
Asked by
Orit
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Orit
Top achievements
Rank 1
Share this question
or