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 and ParentKeyField properties from the relations in the dataset. This also helps in displaying the tables hierarchically by setting the DataSource and DataMemberPath properties of BindingInfo class.
The image below depicts dataset binding in the TreeView control.
To bind TreeView to a DataSet, follow these steps:
C# |
Copy Code
|
---|---|
c1TreeView1.BindingInfo.DataSource = GetData(); |
C# |
Copy Code
|
---|---|
// set the data member path c1TreeView1.BindingInfo.DataMemberPath.Add(0, "Customers"); c1TreeView1.BindingInfo.DataMemberPath.Add(1, "Orders"); c1TreeView1.BindingInfo.DataMemberPath.Add(2, "OrderDetail"); |
C# |
Copy Code
|
---|---|
// 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); |