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

Hierachical GridView from objects.

3 Answers 144 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sergio
Top achievements
Rank 1
Sergio asked on 02 Mar 2008, 06:40 PM
Hi!

I'm trying to to a master-detail view inside a gridview from my own objects but can't get it working ...
trying a details into master object approach only the first item has children , so tryed a object list with parent items and another object list with children items and made a relation inside gridview object but then none of the items have children in the grid ...

Can you help me please?

I've found in this forum about hierachical items from objects not working on jan'07 but the answer from telerik is that it will be solved in q2 release and i'm trying the q3 release , it's possible it's not implemented yet?

thanks

3 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 04 Mar 2008, 05:12 PM
Hi Sergio,

Thank you for contacting us.

Yes, binding to a hierarchy consisting of custom business objects is available in the latest release of RadControls for WinForms. In order to build a hierarchy you just need to add a template and a relation.

Refer to the code snippet below:

public class Client 
    int id; 
    string name; 
 
    public int ID 
    { 
        get { return id; } 
        set { id = value; } 
    } 
 
    public string Name 
    { 
        get { return name; } 
        set { name = value; } 
    } 
 
    public Client(int id, string name) 
    { 
        this.id = id; 
        this.name = name; 
    } 
 
public class Order 
    int id; 
    int clientid; 
    int quantity; 
 
    public int ID 
    { 
        get { return id; } 
        set { id = value; } 
    } 
 
    public int ClientID 
    { 
        get { return clientid; } 
        set { clientid = value; } 
    } 
 
    public int Quantity 
    { 
        get { return quantity; } 
        set { quantity = value; } 
    } 
 
    public Order(int id, int clientid, int quantity) 
    { 
        this.id = id; 
        this.clientid = clientid; 
        this.quantity = quantity; 
    } 
 
 
BindingList<Client> clients = new BindingList<Client>(); 
clients.Add(new Client(1, "John Smith")); 
clients.Add(new Client(2, "Peter Jackson")); 
clients.Add(new Client(3, "Samuel Dell")); 
 
BindingList<Order> orders = new BindingList<Order>(); 
orders.Add(new Order(1, 1, 2)); 
orders.Add(new Order(1, 1, 1)); 
orders.Add(new Order(1, 2, 10)); 
orders.Add(new Order(1, 3, 43)); 
 
this.radGridView1.AutoGenerateHierarchyFromDataSet = false
this.radGridView1.DataSource = clients; 
 
GridViewTemplate ordersTemplate = new GridViewTemplate(this.radGridView1); 
ordersTemplate.DataSource = orders; 
this.radGridView1.MasterGridViewTemplate.ChildGridViewTemplates.Add(ordersTemplate); 
 
GridViewRelation relation = new GridViewRelation(this.radGridView1.MasterGridViewTemplate); 
relation.RelationName = "Clients Orders"
relation.ParentColumnNames.Add("ID"); 
relation.ChildColumnNames.Add("ClientID"); 
relation.ChildTemplate = ordersTemplate; 
this.radGridView1.Relations.Add(relation); 

I hope this helps. Let me know, if you have other questions.

Kind regards,
Jack
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Jonathan Rajotte
Top achievements
Rank 1
answered on 05 May 2008, 09:12 PM
Hi, I've cut & pasted your sample and it doesn't work... nothing shows up in the grid.

Is something missing?

Thanks
0
Jack
Telerik team
answered on 07 May 2008, 01:03 PM
Hi Jonathan,

Thank you for reporting this issue.

Because of changes in RadGridView's data layer the binding behavior has been changed. In order to address the issue, you should first add the relations and then set the DataSource.

Refer to the following sample:

BindingList<Client> clients = new BindingList<Client>(); 
clients.Add(new Client(1, "John Smith")); 
clients.Add(new Client(2, "Peter Jackson")); 
clients.Add(new Client(3, "Samuel Dell")); 
 
BindingList<Order> orders = new BindingList<Order>(); 
orders.Add(new Order(1, 1, 2)); 
orders.Add(new Order(1, 1, 1)); 
orders.Add(new Order(1, 2, 10)); 
orders.Add(new Order(1, 3, 43)); 
 
this.radGridView1.AutoGenerateHierarchyFromDataSet = false
 
GridViewTemplate ordersTemplate = new GridViewTemplate(this.radGridView1); 
ordersTemplate.DataSource = orders; 
this.radGridView1.MasterGridViewTemplate.ChildGridViewTemplates.Add(ordersTemplate); 
 
GridViewRelation relation = new GridViewRelation(this.radGridView1.MasterGridViewTemplate); 
relation.RelationName = "Clients Orders"
relation.ParentColumnNames.Add("ID"); 
relation.ChildColumnNames.Add("ClientID"); 
relation.ChildTemplate = ordersTemplate; 
this.radGridView1.Relations.Add(relation); 
 
this.radGridView1.DataSource = clients; 

I hope this helps. Do not hesitate to write me, if you have other questions

All the best,
Jack
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
GridView
Asked by
Sergio
Top achievements
Rank 1
Answers by
Jack
Telerik team
Jonathan Rajotte
Top achievements
Rank 1
Share this question
or