New to Telerik UI for WPF? Download free 30-day trial

Data Binding

Displaying data in the RadGridView depends on the data binding mechanism. The entry point for the data to be bound is the ItemsSource property, which you must set in order to display data in your RadGridView control.

For additional information regarding data binding and populating the RadTreeListView with data you can check the respective topics in the RadGridView's documentation.

Setting the ItemsSource property

As a typical data control the RadGridView displays data by binding to a source and generating visual elements for each item in it. The first thing that you have to do is to set the ItemsSource property of the RadGridView.

this.radTreeListView.ItemsSource = WarehouseService.GetWarehouseData(); 
Me.radTreeListView.ItemsSource = WarehouseService.GetWarehouseData() 

Types of Sources

Unlike the standard items control, the RadGridView's ItemsSource property is declared to be of type System.Object. Of course, standard .NET collections that implement the IEnumerable interface are fully supported as well. If you want the insertions or the deletions in the collection to be automatically applied to the UI, the collection to which you bind must also implement the INotifyCollectionChanged interface. Coupling in your code, it may be more convenient to manipulate data in the original data source instead of using the RadGridView API. RadGridView listens to data source collection change events and reflects those changes in its visual representation. In Silverlight there is a built-in implementation of a data collection that exposes the INotifyCollectionChanged interface – the ObservableCollection class.

Consider using ObservableCollection or one of the other existing collection classes like List, Collection, instead of implementing your own collection. If the scenario requires a custom collection to be implemented, use the IList interface, which provides individual access by index to its items and the best performance.

Introduced to the System.ComponentModel namespace collection views are fully supported as well. RadGridView will automatically pick up group descriptions, sort descriptions, or will filter settings defined on the collection view and will use those settings to display data.

Binding the Columns

The data in the RadGridView is separated in columns. There are different types of columns, displaying different types of data. Usually the data is displayed in GridViewDataColumns, which can be manually generated, too. In order to display the data in it you can bind its DataMemberBinding property. Here is an example of a manually defined column.

<telerik:RadTreeListView x:Name="radTreeListView" 
        <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}" 
                                    Header="Name" /> 
        <telerik:GridViewDataColumn DataMemberBinding="{Binding Count}" 
                                    Header="Count" /> 

Binding the TreeListViewTableDefinitions

In order to display the hierarchical data the RadTreeListView uses child table definition of type TreeListViewTableDefinition. In order to display the underlying items in the hierarchy you have to bind its ItemsSource to the appropriate property.

Note that a table definition will be generated for each row and it will have the same DataContext as the row. So you have to bind to the property, marking the collection that contains the next level of the hierarchy. This property should have the same name at each level of the hierarchy.

<telerik:RadTreeListView x:Name="radTreeListView"> 
        <telerik:TreeListViewTableDefinition ItemsSource="{Binding Items}"> 

See Also

In this article