![wpf treeview style examples wpf treeview style examples](http://imaginativethinking.ca/blog/wp-content/uploads/2015/07/TreeModelSchematic.png)
In the code below, we get the first default column that is added and sets its DisplayFieldName and HeaderText properties. Create an AddColumns method, and as mentioned earlier, we will add CategoryName and Description from the Categories table. We can now add the columns we want to display to the TreeView. We assign the KeyField to CategoryID and then set the data source. Note that we use the DataMemberPath property to assign Categories and Products Tables at the first and second level. private void GetData()ĬategoriesTableAdapter.Fill(ds.Categories) Ĭ = "Categories" Ĭ = "Products" Ĭ = "CategoryID" ProductsTableAdapter = new C1NWindDataSetTableAdapters.ProductsTableAdapter() ĬategoriesTableAdapter = new C1NWindDataSetTableAdapters.CategoriesTableAdapter() Īdd a GetData method and fill in the dataset. Initialize the dataset, CategoriesTableAdapter and ProductsTableAdapter objects in the form constructor: C1NWindDataSetTableAdapters.ProductsTableAdapter productsTableAdapter Ĭ1NWindDataSetTableAdapters.CategoriesTableAdapter categoriesTableAdapter The above added the tables, as well as the CategoriesTableAdapter and ProductsTableAdapter, to the project.Īdd a C1TreeView control to the form and switch to code view. Dragged and dropped the Categories and Products table to the dataset.In a WinForms project, we created a connection to the Northwind database and added a dataset named C1NorthwindDataset to the project.The Northwind database already has a relationship between the Categories and Products table, where each category can have many products. We want to display Category & Description from the Categories table at the first level and ProductName, QuantityPerUnit, and UnitPrice from the Products table at the second level. We will bind the TreeView to Northwind Categories and Products data. Ready to get started with TreeView? Download a FREE trial of ComponentOne! Create the Data Source In this blog, we will see how a TreeView can be bound to hierarchical data with multiple columns in three easy steps: The ComponentOne WinForms TreeView provides additional features like adding, removing, and editing nodes, showing multiple columns, drag & drop, and node customization. A TreeView control provides an excellent interface to visualize hierarchical data with multiple item selection.