1 |
//clear the gridview of everything |
2 |
rgvNetwork.MasterGridViewTemplate.Columns.Clear(); |
3 |
radGridView.MasterGridViewTemplate.Rows.Clear(); |
4 |
radGridView.MasterGridViewTemplate.ChildGridViewTemplates.Clear(); |
5 |
|
6 |
|
7 |
//add the columns for the master |
8 |
radGridView.MasterGridViewTemplate.Columns.Add(new GridViewDataColumn { FieldName = "Id", HeaderText = "Name", HeaderTextAlignment = ContentAlignment.MiddleCenter }); |
9 |
radGridView.MasterGridViewTemplate.Columns.Add(new GridViewDataColumn { FieldName = "Name", HeaderText = "Adserver Id", HeaderTextAlignment = ContentAlignment.MiddleCenter }); |
10 |
radGridView.MasterGridViewTemplate.Columns.Add(new GridViewDataColumn { FieldName = "Active", HeaderText = "Active", HeaderTextAlignment = ContentAlignment.MiddleCenter }); |
11 |
|
12 |
//add the columns for the childs |
13 |
var template = new GridViewTemplate { AllowAddNewRow = false, AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill }; |
14 |
template.Columns.Add(new GridViewTextBoxColumn { FieldName = "Id", IsVisible = false }); |
15 |
template.Columns.Add(new GridViewTextBoxColumn { FieldName = "IdChild", HeaderText = "Zone Name", HeaderTextAlignment = ContentAlignment.MiddleCenter}); |
16 |
template.Columns.Add(new GridViewTextBoxColumn { FieldName = "NameChild", HeaderText = "Zone Id", HeaderTextAlignment = ContentAlignment.MiddleCenter}); |
17 |
|
18 |
//add the childtemplate to the master |
19 |
radGridView.MasterGridViewTemplate.ChildGridViewTemplates.Add(template); |
20 |
|
21 |
//make the relationship between master and child |
22 |
var relation = new GridViewRelation(radGridView.MasterGridViewTemplate) |
23 |
{ |
24 |
ChildTemplate = template, |
25 |
RelationName = "SiteZonesNetwork" |
26 |
}; |
27 |
|
28 |
relation.ParentColumnNames.Add("Id"); //equals the fieldname |
29 |
relation.ChildColumnNames.Add("Id"); //equals the fieldname |
30 |
|
31 |
//add the relation |
32 |
radGridView.Relations.Add(relation); |
33 |
|
34 |
|
35 |
//load your List<Master> |
36 |
var myListMaster = new List<Master>(); |
37 |
|
38 |
var child1 = new List<Child>(); |
39 |
child1.Add(new Child{ Id = 2, Name = "ChildTest2" }); |
40 |
child1.Add(new Child{ Id = 3, Name = "ChildTest3" }); |
41 |
|
42 |
var child2 = new List<Child>(); |
43 |
child1.Add(new Child{ Id = 5, Name = "ChildTest5" }); |
44 |
child1.Add(new Child{ Id = 6, Name = "ChildTest6" }); |
45 |
child1.Add(new Child{ Id = 7, Name = "ChildTest7" }); |
46 |
|
47 |
myListMaster.Add(new Master { Id = 1, Name = "Test", Childs = child1 }); |
48 |
myListMaster.Add(new Master { Id = 4, Name = "Test2", Childs = child2 }); |
49 |
|
50 |
|
51 |
//fill the radgridview |
52 |
foreach(var myMaster in myListMaster){ |
53 |
|
54 |
radGridView.MasterGridViewTemplate.Rows.Add(new object[] { myMaster.Id, myMaster.Name, myMaster.Active }); |
55 |
template = radGridView.MasterGridViewTemplate.ChildGridViewTemplates[0]; |
56 |
|
57 |
foreach(var child in myMaster.childs){ |
58 |
|
59 |
template.Rows.Add(new object[] { myMaster.Id, child.Id, child.Name }); |
60 |
} |
61 |
|
62 |
} |