# DataSet Binding

Get started with TreeView, a WinForms control to help users display a hierarchical item list. See more in documentation here.

## Content

Just like binding with relational lists, TreeView can be bound to relational datasets, where relationships are defined between individual tables. The TreeView control can automatically generate the [KeyField](/componentone/api/win/online-treeview/dotnet-api/C1.Win.TreeView.10/C1.Win.TreeView.BindingInfo.KeyField.html) and [ParentKeyField](/componentone/api/win/online-treeview/dotnet-api/C1.Win.TreeView.10/C1.Win.TreeView.BindingInfo.ParentKeyField.html) properties from the relations in the dataset. This also helps in displaying the tables hierarchically by setting the [DataSource](/componentone/api/win/online-treeview/dotnet-api/C1.Win.TreeView.10/C1.Win.TreeView.BindingInfo.DataSource.html) and [DataMemberPath](/componentone/api/win/online-treeview/dotnet-api/C1.Win.TreeView.10/C1.Win.TreeView.BindingInfo.DataMemberPath.html) properties of [BindingInfo](/componentone/api/win/online-treeview/dotnet-api/C1.Win.TreeView.10/C1.Win.TreeView.BindingInfo.html) class.

The image below depicts dataset binding in the TreeView control.

![TreeView UI](https://cdn.mescius.io/document-site-files/images/56bb69d1-e225-4d79-8965-f70a0e789043/images/treeview-automatic-generation.png)

To bind TreeView to a DataSet, follow these steps:

1. Set the datasource for TreeView using the [DataSource](/componentone/api/win/online-treeview/dotnet-api/C1.Win.TreeView.10/C1.Win.TreeView.BindingInfo.DataSource.html) property. Note that here we fetch the data from the **DataSet** class using the **GetData** method.

    ```csharp
    c1TreeView1.BindingInfo.DataSource = GetData();
    ```
2. Set the data members for tree levels.

    ```csharp
    // set the data member path
    c1TreeView1.BindingInfo.DataMemberPath.Add(0, "Customers");
    c1TreeView1.BindingInfo.DataMemberPath.Add(1, "Orders");
    c1TreeView1.BindingInfo.DataMemberPath.Add(2, "OrderDetail");
    ```
3. Configure and add the columns to be displayed in the TreeView. Set the [DisplayFieldName](/componentone/api/win/online-treeview/dotnet-api/C1.Win.TreeView.10/C1.Win.TreeView.C1TreeColumn.DisplayFieldName.html) property to get the list of fields to be displayed in the columns and the [DisplayMemberPath](/componentone/api/win/online-treeview/dotnet-api/C1.Win.TreeView.10/C1.Win.TreeView.C1TreeColumn.DisplayMemberPath.html) property to get a collection that identifies the fields to be displayed in a column depending on the node level.

    ```csharp
    // configure columns
    // ID
    var column = c1TreeView1.Columns[0];
    column.DisplayFieldName = "ID";
    column.HeaderText = "ID";
    // Customer info
    column = new C1.Win.TreeView.C1TreeColumn();
    column.DisplayMemberPath.Add(0, "Name");
    column.DisplayMemberPath.Add(1, "CustomerID");
    column.DisplayMemberPath.Add(2, "OrderID");
    column.HeaderText = "Customer info";
    c1TreeView1.Columns.Add(column);
    // Order Info
    column = new C1.Win.TreeView.C1TreeColumn();
    column.DisplayMemberPath.Add(0, "Address");
    column.DisplayMemberPath.Add(1, "Date");
    column.DisplayMemberPath.Add(2, "Qty");
    column.HeaderText = "Order Info";
    c1TreeView1.Columns.Add(column);
    ```