To bind the RadTreeView to a collection use its ItemsSource property and define HierarchicalDataTemplate that are needed to display the data from the collection. If you want the changes to the collection to be automatically reflected to the RadTreeView items, the collection should inherit from ObservableCollection, or to implement the INotifyPropertyChanged interface.

The following tutorial will guide you how to bind a RadTreeView to a collection of business objects.

The final result should look like the snapshot below:

First, you need to include the following assemblies in your XAML declaration:

Telerik.Windows.Controls

Telerik.Windows.Controls.Navigation

Create a new class named Team. The class has a single string property.

Public Class Team
Public Sub New(ByVal name As String)
Me.Name = name
End Sub
Private _Name As String
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal value As String)
_Name = value
End Set
End Property
End Class

Create a new class named Division. The class has a single string property - Name and a collection with teams.

Public Class Division
Public Sub New(ByVal name As String)
Me.Name = name
Me.Teams = New ObservableCollection(Of Team)()
End Sub
Private _Name As String
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal value As String)
_Name = value
End Set
End Property
Private _Teams As ObservableCollection(Of Team)
Public Property Teams() As ObservableCollection(Of Team)
Get
Return _Teams
End Get
Set(ByVal value As ObservableCollection(Of Team))
_Teams = value
End Set
End Property
End Class

Create a new class named League. The class has a single string property and a collection with divisions objects. Practically, a collection of League objects will be the data source for the treeview.

Public Class League
Public Sub New(ByVal name As String)
Me.Name = name
Me.Divisions = New ObservableCollection(Of Division)()
End Sub
Private _Name As String
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal value As String)
_Name = value
End Set
End Property
Private _Divisions As ObservableCollection(Of Division)
Public Property Divisions() As ObservableCollection(Of Division)
Get
Return _Divisions
End Get
Set(ByVal value As ObservableCollection(Of Division))
_Divisions = value
End Set
End Property
End Class

Create a new class named RadTreeViewSampleData. This will be the data source (the model) for the RadTreeView. The class has a reference to an ObservableCollection of League objects and a single method which initializes the data.

Was this article helpful?

/

Give article feedback

Tell us how we can improve this article

Code samples are inaccurate / outdated.
I expected to find other / more information.
There are typos / broken links / broken page elements.
Content is inaccurate / outdated.
Other
By checking this box you consent to Progress contacting you by email about your response on this page.

Community

Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks for appropriate markings.