# Tutorial: Binding to Hierarchical Data

| RELATED VIDEOS                                                                                                                                                                                                                                            |                                                                                                                                                                                                                               |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [RadGridView for WinForms Hierarchy Overview](http://tv.telerik.com/watch/winforms/radgrid/radgridview-winforms-hierarchy-overview)<br>In this video you will learn the various ways you can display hierarchical data in a RadGridView. (Runtime: 12:13) | ![WinForms RadGridView Binding to Hierarchical Data Tutorial](https://www.telerik.com/products/winforms/documentation/assets/619ce88f604aac6ad8a447f6afc48e58/gridview-hierarchical-grid-binding-to-hierarchical-data001.png) |

The following tutorial demonstrates configuring the grid to display multiple tables in a hierarchy. The example below uses the Northwind `Categories` table as the parent table and lists the appropriate `Product` table records below each category. The tutorial only uses the two tables, but the example can be extended to larger numbers of child tables.

![WinForms RadGridView Hierarchical Data](https://www.telerik.com/products/winforms/documentation/assets/78813ab80ae5e704573b768ad6d497ae/gridview-hierarchical-grid-tutorial-binding-to-hierarchical-data020.png)

The task has 3 basic steps:

1. Configure data sources.

2. Define child grid view templates, one for each level in the hierarchy.

3. Define relations between parent and child tables.

## Configure Data Sources

1. Place a RadGridView component on a form. Set the **Dock** property to *Fill*.

2. In the Properties window locate the **DataSource** property and click the arrow to open the list. Select the **Add Project Data Source...** link.  *This step will display the Data Source Configuration Wizard.*
   ![WinForms RadGridView gridview-hierarchical-grid-tutorial-binding-to-hierarchical-data 001](https://www.telerik.com/products/winforms/documentation/assets/d0b6ecd68d8c22da306e4cfa34183560/gridview-hierarchical-grid-tutorial-binding-to-hierarchical-data001.png)

3. In the Data Source Configuration Wizard, Choose a Data Source Type page, select the **Database** icon. Click the **Next** button.

   ![WinForms RadGridView Data Source Type](https://www.telerik.com/products/winforms/documentation/assets/8f2f22f1e97353e1c1ffbfd68d9319cf/gridview-hierarchical-grid-tutorial-binding-to-hierarchical-data002.png)

4. In the Database Model page of the Data Source Configuration Wizard choose **Database** icon. Click the **Next** button.

   ![WinForms RadGridView Database](https://www.telerik.com/products/winforms/documentation/assets/48deb85a06126d25bb61880e82caaac7/gridview-hierarchical-grid-tutorial-binding-to-hierarchical-data003.png)

5. In the `Choose Your data Connection` page click the **New Connection...** button. \*This step will display the Add Connection dialog. \* Add the connection and then click **Next**.

   ![WinForms RadGridView New Connection](https://www.telerik.com/products/winforms/documentation/assets/8d401f288bbf6d29771902e0ad7ae7d3/gridview-hierarchical-grid-tutorial-binding-to-hierarchical-data004.png)

6. Click the **Next** to save the ConnectionString name:

   ![WinForms RadGridView ConnectionString](https://www.telerik.com/products/winforms/documentation/assets/026320e2094540d5a71025f9e2e2f534/gridview-hierarchical-grid-tutorial-binding-to-hierarchical-data009.png)

7. In the Choose Your Database Objects page, select the **"Categories"** and **"Products"** checkboxes. Click the **Finish** button to close the Data Source Configuration Wizard.

   ![WinForms RadGridView Categories and Products](https://www.telerik.com/products/winforms/documentation/assets/c2650c1fb1e8c2311e14b4e4cb8aee4b/gridview-hierarchical-grid-tutorial-binding-to-hierarchical-data010.png)

8. In the Visual Studio Properties window for the grid **DataSource** property select the "Products" table. \* This step will create DataSet, BindingSource and TableAdapter objects for the products table.\*

   ![WinForms RadGridView Products Table](https://www.telerik.com/products/winforms/documentation/assets/fb6d846f89c8a2c6909ca8237f702578/gridview-hierarchical-grid-tutorial-binding-to-hierarchical-data011.png)

9. In the Visual Studio Properties window for the grid **DataSource** property select the "Categories" table. \* This step will create DataSet, BindingSource and TableAdapter objects for the categories table.\*

   ![WinForms RadGridView Categories Table](https://www.telerik.com/products/winforms/documentation/assets/75ebc64250872af4c10f493f0b9b0673/gridview-hierarchical-grid-tutorial-binding-to-hierarchical-data012.png) 

10. The project design should look similar to the below image. The **DataSource** property should be left to point at the binding source of the `Categories` table. Note the new data components in the component tray under the design surface.

    ![WinForms RadGridView DataSource Property](https://www.telerik.com/products/winforms/documentation/assets/4a5362da4e1e1f48e3242d3b99795de4/gridview-hierarchical-grid-tutorial-binding-to-hierarchical-data013.png)

## Define Child Templates

1. In the `Properties` window click the ellipses for the **Templates** property. *This step will display the GridViewTemplate Collection Editor.*

   ![WinForms RadGridView Templates](https://www.telerik.com/products/winforms/documentation/assets/2965b2f6b098bb07c0725e519ac337ae/gridview-hierarchical-grid-tutorial-binding-to-hierarchical-data014.png)

2. In the GridViewTemplate Collection Editor, click the **Add** button to add a child grid view template. In the properties for the new grid view template, use the **DataSource** property drop down to locate and select the binding source of the data table **"Products"**. Click the **OK** button to close the dialog.

   ![WinForms RadGridView Add Child Grid](https://www.telerik.com/products/winforms/documentation/assets/1d82ef63c30803c787ad37a33e711083/gridview-hierarchical-grid-tutorial-binding-to-hierarchical-data015.png)

## Define relations

1. In the `Properties` window click the ellipses for the grid **Relations** property. *This will display the GridViewRelation Collection Editor.*

   ![WinForms RadGridView Relations](https://www.telerik.com/products/winforms/documentation/assets/c5fb82a173b0dbe3a0533e7b50473757/gridview-hierarchical-grid-tutorial-binding-to-hierarchical-data016.png)

2. In the `GridViewRelation Collection Editor`, click the **Add** button to add a relation. *The relation will describe the parent/child relationship between the category data (parent table) and the products (child table) for each category.*

3. Set the **RelationName** property to "CategoryProduct".

4. Set the GridViewRelation **ChildTemplate** property to the child grid view template (created earlier in the GridViewTemplate Collection Editor) using the drop down list.

   ![WinForms RadGridView ChildTemplate](https://www.telerik.com/products/winforms/documentation/assets/f32d0961361260b8aba3b74c32447820/gridview-hierarchical-grid-tutorial-binding-to-hierarchical-data019.png)

5. Set the **ParentTemplate** property to the **MasterTemplate**.

6. Click the ellipses for the **ChildColumnName** property. *This will display the ColumnName Collection Editor.*

7. In the ColumnName Collection Editor click the **Add** button and set the column **Name** property to "CategoryID". Click the **OK** button to close the dialog.

   ![WinForms RadGridView CategoryID](https://www.telerik.com/products/winforms/documentation/assets/95f3e1fa730c43e39a6fad6a668a730e/gridview-hierarchical-grid-tutorial-binding-to-hierarchical-data017.png)

8. Click the ellipses for the **ParentColumnName** property. In the ColumnName Collection Editor click the **Add** button and set the column **Name** property to "CategoryID". Click the **OK** button to close the dialog.

9. Press **F5** to run the application.

## See Also

* [Binding to Hierarchical Data Automatically](https://www.telerik.com/products/winforms/documentation/controls/gridview/hierarchical-grid/binding-to-hierarchical-data-automatically)

* [Binding to Hierarchical Data Programmatically](https://www.telerik.com/products/winforms/documentation/controls/gridview/hierarchical-grid/binding-to-hierarchical-data-programmatically)

* [Binding to Hierarchical Data](https://www.telerik.com/products/winforms/documentation/controls/gridview/hierarchical-grid/binding-to-hierarchical-data)

* [Creating hierarchy using an XML data source](https://www.telerik.com/products/winforms/documentation/controls/gridview/hierarchical-grid/creating-hierarchy-using-an-xml-data-source)

* [Hierarchy of one to many relations](https://www.telerik.com/products/winforms/documentation/controls/gridview/hierarchical-grid/hierarchy-of-one-to-many-relations)

* [Load-On-Demand Hierarchy](https://www.telerik.com/products/winforms/documentation/controls/gridview/hierarchical-grid/load-on-demand-hierarchy)

* [Object Relational Hierarchy Mode](https://www.telerik.com/products/winforms/documentation/controls/gridview/hierarchical-grid/object-relational-hierarchy-mode)

* [Self-Referencing Hierarchy](https://www.telerik.com/products/winforms/documentation/controls/gridview/hierarchical-grid/self-referencing-hierarchy)
