# Binding to Object-relational Data

RadTreeView has the ability to bind to related data of custom objects which have member collections of related objects (ORM generated classes for example).

Consider the following class diagram:

![WinForms RadTreeView OR Class Diagram](https://www.telerik.com/products/winforms/documentation/assets/30fce8073035eacc50b87fdd4f1e2e6e/treeview-data-binding-binding-to-object-relational-data004.png)

There are three classes named **Customer**, **Order** and **Order_Detail**. The data relations in the case of custom objects are represented by properties which provide references to collections of related objects. In this case the **Customer** class has a property named **Orders** which is a collection of **Order** objects. This is the first relation. The second relation is the **Order_Details** property in the **Order** class, it offers a reference to a collection of **Order_Details**. Once you have such class composition, it is trivial for RadTreeView to represent it visually in your application.

The two steps that must be done are these:

1\. Set the DataSource of RadTreeView to a collection of your root objects (a collection of Customer object in this case):

```C#
IEnumerable<Customer> customers = context.GetTable<Customer>().ToList();       
this.radTreeView1.DataSource = customers;

```

```VB.NET
Dim customers As IEnumerable(Of Customer) = context.GetTable(Of Customer)().ToList()
Me.RadTreeView1.DataSource = customers
```

> note The above context object is created by binding the project to the NorthWind database using [LINQ to SQl](https://msdn.microsoft.com/en-us/library/bb386976\(v=vs.110\).aspx)

2\. Set the **DisplayMember** corresponding to the DisplayMembers of the different types of objects and set the **ChildMember** corresponding to the names of the properties that represent the collections of sub objects.

```C#
this.radTreeView1.DisplayMember = "ContactName\\ShipName\\UnitPrice";
this.radTreeView1.ChildMember = "Customers\\Orders\\Order_Details";
        
```

```VB.NET
Me.RadTreeView1.DisplayMember = "ContactName\ShipName\UnitPrice"
Me.RadTreeView1.ChildMember = "Customers\Orders\Order_Details"
```

As a result, we get the following hierarchy in RadTreeView:

![WinForms RadTreeView Binding to Object-relational Data](https://www.telerik.com/products/winforms/documentation/assets/7404500b4f29999bf4c82ffd6c601d3c/treeview-data-binding-binding-to-object-relational-data001.png)

## See Also

* [Binding to Database Data](https://www.telerik.com/products/winforms/documentation/controls/treeview/data-binding/binding-to-database-data)

* [Binding to Self Referencing Data](https://www.telerik.com/products/winforms/documentation/controls/treeview/data-binding/binding-to-self-referencing-data)

* [Binding to XML Data](https://www.telerik.com/products/winforms/documentation/controls/treeview/data-binding/binding-to-xml-data)

* [Data Binding](https://www.telerik.com/products/winforms/documentation/controls/treeview/data-binding/overview)

* [Binding CheckBoxes](https://www.telerik.com/products/winforms/documentation/controls/treeview/data-binding/databinding-checkboxes)

* [Serialize/Deserialize to XML](https://www.telerik.com/products/winforms/documentation/controls/treeview/data-binding/deserialize-to-xml)
