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

Hierarchy relation problem?

2 Answers 82 Views
GridView
This is a migrated thread and some comments may be shown as answers.
gerbrand
Top achievements
Rank 2
gerbrand asked on 06 Apr 2009, 09:13 AM
Hi,

I'm trying to display a 3 level hierarchy into the gridview. I have no problem when I have a 2 level hierarchy. With the 3 level hierarchy I only get the first 2 levels. Now I guess I'm doing something wrong in the relations. But I can't seem to find the mistake or is it something else?

My code:

//add columns and relations 
rgvAdserver.MasterGridViewTemplate.Columns.Add(new GridViewDataColumn { FieldName = "SiteId", HeaderText = "Site Id", HeaderTextAlignment = ContentAlignment.MiddleCenter }); 
rgvAdserver.MasterGridViewTemplate.Columns.Add(new GridViewDataColumn { FieldName = "SiteName", HeaderText = "Site Name", HeaderTextAlignment = ContentAlignment.MiddleCenter }); 
 
var template = new GridViewTemplate { AllowAddNewRow = false, AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill }; 
template.Columns.Add(new GridViewTextBoxColumn { FieldName = "SiteId", IsVisible = false }); 
template.Columns.Add(new GridViewTextBoxColumn { FieldName = "ZoneId", HeaderText = "Zone Id", HeaderTextAlignment = ContentAlignment.MiddleCenter }); 
template.Columns.Add(new GridViewTextBoxColumn { FieldName = "ZoneName", HeaderText = "Zone Name", HeaderTextAlignment = ContentAlignment.MiddleCenter }); 
 
var templateAdslot = new GridViewTemplate { AllowAddNewRow = false, AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill }; 
templateAdslot.Columns.Add(new GridViewDataColumn{FieldName = "ZoneId", IsVisible = false }); 
templateAdslot.Columns.Add(new GridViewDataColumn{FieldName = "Adslot", HeaderText = "Adslot size", HeaderTextAlignment = ContentAlignment.MiddleCenter }); 
 
//add rows template 
rgvAdserver.MasterGridViewTemplate.ChildGridViewTemplates.Add(template); 
rgvAdserver.MasterGridViewTemplate.ChildGridViewTemplates.Add(templateAdslot); 
 
//create relation between both 
var relation = new GridViewRelation(rgvAdserver.MasterGridViewTemplate) 
                   { 
                       ChildTemplate = template, 
                       RelationName = "SiteZonesNetwork" 
                   }; 
 
relation.ParentColumnNames.Add("SiteId"); 
relation.ChildColumnNames.Add("SiteId"); 
rgvAdserver.Relations.Add(relation); 
 
var relation2 = new GridViewRelation(template) 
               { 
                   ChildTemplate = templateAdslot, 
                   RelationName = "zoneAdslot" 
               }; 
relation2.ParentColumnNames.Add("ZoneId"); 
relation2.ChildColumnNames.Add("ZoneId"); 
rgvAdserver.Relations.Add(relation2); 
 
//add data 
rgvAdserver.MasterGridViewTemplate.Rows.Clear(); 
 
GridViewTemplate template = null
GridViewTemplate templateAdslot = null
 
foreach(var data in gridData) 
 
    rgvAdserver.MasterGridViewTemplate.Rows.Add(new object[] { data.siteid, data.sitename }); 
     
    template = rgvAdserver.MasterGridViewTemplate.ChildGridViewTemplates[0]; 
    templateAdslot = rgvAdserver.MasterGridViewTemplate.ChildGridViewTemplates[1]; 
    template.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill; 
    templateAdslot.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill; 
     
    foreach(var zone in data.dartzones) 
    { 
        template.Rows.Add(new object[] { data.siteid, zone.zoneid, zone.zonename }); 
 
        foreach(var adslot in zone.adslots) 
        { 
            templateAdslot.Rows.Add(new object[] { zone.zoneid, adslot.adslotsize }); 
        } 
    } 
 
 
 
 

Thanks in advanced.


2 Answers, 1 is accepted

Sort by
0
Accepted
Jack
Telerik team
answered on 08 Apr 2009, 11:24 AM
Hi Gerbrand,

You should add GridViewTemplate that represents the third level as a child for the template representing the second level in hierarchy. Consider the code snippet below:

rgvAdserver.MasterGridViewTemplate.ChildGridViewTemplates.Add(template); 
template.ChildGridViewTemplates.Add(templateAdslot); 

I hope this helps. If you need further assistance, I will be glad to help.

Greetings,
Jack
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
gerbrand
Top achievements
Rank 2
answered on 08 Apr 2009, 12:48 PM
Arghh!!, how stupid of me. I knew it would be something simple. 

Okay thanks a lot, now it works.


Tags
GridView
Asked by
gerbrand
Top achievements
Rank 2
Answers by
Jack
Telerik team
gerbrand
Top achievements
Rank 2
Share this question
or