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.