$99 VS $1000+. UI Control for ASP.NET AJAX(contains chart and gridview).
WinForms TreeView Control
Build complex navigation systems and display complex hierarchical structures
Home > WinForms UI Controls > User Manual > Data Binding Basics in C#

KetticTreeView Data Binding to Objects in C#.NET

KetticTreeView control for Windows Forms provides powerful data binding capability and the developers can just configure a simple property of the control to bind the TreeView to any data sources or object that implements IList, IListSource, IBindingList, generic lists, and BindingSource, in your Window Forms development environment. The business objects data binding of KetticTreeView is achieved by using the DataSource property of this tree view component. The following C# tutorial demonstrates how to bind the TreeView to objects

Properties for Binding KetticTreeView to Data Objects

  • DataSource, this property is assigned to the KetticTreeView control for data binding to objects
  • ShowMember, we shall assign the name of the field that we are going to show in the tree view to this property
  • ValueMember, we shall set the name of a field stored in the Value property of the nodes to this property

C# Binding KetticTreeView to Generic List in Windows Forms

In the C# code snippet sample below, we are going to bind the KetticTreeView to a generic list of an object to display only one data level. This generic list object contains three fields, an integer, a char, and a string. We shall assign the ValueMember property to the int field and assign the ShowMember to the string field.

C# Getting Object Bound to Data for Node in KetticTreeView

After we bind the KetticTreeView to generic list object, we can also to get the data from the object. The following C# code example demonstrates how to get the price of a Student as we selecting node of the Student. The price message will be shown in the message box when we choose a node.

void ketticTreeView1_SelectedNodeChanged(object sender, Kettic.WinForms.UI.KetticTreeViewEventArgs e)
{
Student Student = e.Node.DataBoundItem as Student;
if (Student != null)
{
MessageBox.Show("Student: " + e.Node.Text + ", Age: " + Student.Age);
}
}
In addition, when we initially set an item bound data to the KetticTreeNode, it will fire the NodeDataBound event, which can help you to sync the properties of KetticTreeNode with those of the data bound item. The C# code below shows the process.

void ketticTreeView1_NodeDataBound(object sender, Kettic.WinForms.UI.KetticTreeViewEventArgs e)
{
DataRowView dataRow = e.Node.DataBoundItem as DataRowView;
if(dataRow != null)
{
e.Node.ForeColor = (Color)dataRow["ForeColor"];
}
}

C# Data Binding to Show Hierarchical data in KetticTreeView

This is the highlight feature of the KetticTreeView control for WinForms. The developers can bind this control to the hierarchical data and display the hierarchy of custom object. The following C# code sample will contains a Grade parent level, in which the Grade will contains various Classes and has the only Grade Name property and a list of classes. To show the hierarchy of business objects, we shall assign appropriate values to the ShowMember and ChildMember properties.
UI Controlsfor Windows Forms
.NET WinForms UI Overview.NET WinForms UI Features.NET WinForms UI GuideC# WinForms UI DesignVB.NET WinForms UI Design
WinForms UI Controls