Edit this page

Configuring the Data Bindings

Setting the ItemsSource

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 you have to do is to set the ItemsSource property of RadGridView.

C#

this.radGridView.ItemsSource = SampleData.GetData();

VB.NET

Me.radGridView.ItemsSource = SampleData.GetData()

Types of Sources

Unlike a 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 bound 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 WPF there is a built-in implementation of a data collection that exposes the INotifyCollectionChanged interface – the ObservableCollection class.

When binding the ItemsSource to a DataTable, you should use its DefaultView property.

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 filter settings defined on the collection view and use those 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. Here is an example of a manually defined column.

XAML

<telerik:RadGridView x:Name="radGridView"
                 AutoGenerateColumns="False">
    <telerik:RadGridView.Columns>
        <telerik:GridViewDataColumn DataMemberBinding="{Binding Id}"
                                Header="Id" />
    </telerik:RadGridView.Columns>
</telerik:RadGridView>

To learn more about defining columns and the different types of columns take a look at the Grid Columns section.

See Also