Hierarchy relation problem?

3 posts, 1 answers
  1. gerbrand
    gerbrand avatar
    78 posts
    Member since:
    Mar 2009

    Posted 06 Apr 2009 Link to this post

    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. Answer
    Jack
    Admin
    Jack avatar
    2335 posts

    Posted 08 Apr 2009 Link to this post

    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.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. gerbrand
    gerbrand avatar
    78 posts
    Member since:
    Mar 2009

    Posted 08 Apr 2009 Link to this post

    Arghh!!, how stupid of me. I knew it would be something simple. 

    Okay thanks a lot, now it works.


Back to Top