Hello,
I am trying to create a RadGridView which have multiple GridViewTemplates as hierarchical data. It works for my first relation using ParentColumnNames and ChildColumnNames, however, when adding my second relation, it does not work.
A small attached code sample is here, thanks:
I am trying to create a RadGridView which have multiple GridViewTemplates as hierarchical data. It works for my first relation using ParentColumnNames and ChildColumnNames, however, when adding my second relation, it does not work.
A small attached code sample is here, thanks:
public class Client |
{ |
public int ID { get; set; } |
public string Name { get; set; } |
public Client(int id, string name) |
{ |
ID = id; |
Name = name; |
} |
} |
public class Order |
{ |
public int ID { get; set; } |
public int ClientID { get; set; } |
public int Quantity { get; set; } |
public Order(int id, int clientid, int quantity) |
{ |
ID = id; |
ClientID = clientid; |
Quantity = quantity; |
} |
} |
public class OrderPrices |
{ |
public int ID { get; set; } |
public int ClientID { get; set; } |
public double Price { get; set; } |
public OrderPrices(int id, int clientid, double price) |
{ |
ID = id; |
ClientID = clientid; |
Price = price; |
} |
} |
private void Form1_Load(object sender, EventArgs e) |
{ |
radGridView1.AutoGenerateHierarchyFromDataSet = false; |
ordersTemplate = new GridViewTemplate(this.radGridView1); |
radGridView1.MasterGridViewTemplate.ChildGridViewTemplates.Add(ordersTemplate); |
GridViewRelation relation1 = new GridViewRelation(this.radGridView1.MasterGridViewTemplate); |
relation1.RelationName = "Clients Orders1"; |
relation1.ParentColumnNames.Add("ID"); |
relation1.ChildColumnNames.Add("ClientID"); |
relation1.ChildTemplate = ordersTemplate; |
radGridView1.Relations.Add(relation1); |
orderPricesTemplate = new GridViewTemplate(radGridView1); |
radGridView1.MasterGridViewTemplate.ChildGridViewTemplates.Add(orderPricesTemplate); |
GridViewRelation relation2 = new GridViewRelation(radGridView1.MasterGridViewTemplate); |
relation2.RelationName = "Clients Order Prices"; |
relation2.ParentColumnNames.Add("ID"); |
relation2.ChildColumnNames.Add("ClientID"); |
relation2.ChildTemplate = orderPricesTemplate; |
radGridView1.Relations.Add(relation2); |
LoadData(); |
} |
private void LoadData() |
{ |
BindingList<Client> clients = new BindingList<Client> |
{ |
new Client(1, "John Smith"), |
new Client(2, "Peter Jackson"), |
new Client(3, "Samuel Dell"), |
new Client(4, "Test") |
}; |
BindingList<Order> orders = new BindingList<Order> |
{ |
new Order(1, 1, 2), |
new Order(1, 1, 1), |
new Order(1, 2, 10), |
new Order(1, 3, 43) |
}; |
BindingList<OrderPrices> orderprices = new BindingList<OrderPrices> |
{ |
new OrderPrices(1, 4, 1.50), |
new OrderPrices(1, 4, 9.99), |
new OrderPrices(1, 1, 10.11), |
new OrderPrices(1, 2, 43.42) |
}; |
orderPricesTemplate.DataSource = orderprices; |
ordersTemplate.DataSource = orders; |
radGridView1.DataSource = clients; |
} |