Sorting
RadGridView provides you with a built-in sorting functionality, which allows the user to easily sort the data by one of the columns.
You can define sorting criteria either in the XAML or in the code-behind.
<telerik:RadGridView x:Name="radGridView"
AutoGenerateColumns="False">
<telerik:RadGridView.SortDescriptors>
<telerik:SortDescriptor Member="EmployeeID"
SortDirection="Ascending" />
</telerik:RadGridView.SortDescriptors>
<!--...-->
</telerik:RadGridView>
You can achieve the same result if you define your sorting criteria in the code-behind like this:
SortDescriptor descriptor = new SortDescriptor();
descriptor.Member = "EmployeeID";
descriptor.SortDirection = ListSortDirection.Ascending;
this.radGridView.SortDescriptors.Add(descriptor);
Dim descriptor As New SortDescriptor()
descriptor.Member = "EmployeeID"
descriptor.SortDirection = ListSortDirection.Ascending
Me.radGridView.SortDescriptors.Add(descriptor)
Note that since SortDescriptors property is a collection, you can add more than one SortDescriptor to a RadGridView.
Consider using the code-behind approach only when changing the sorting criteria run-time.
If the RadGridView is bound to a collection that inherits ICollectionView that has a CanSort property set to true, the RadGridView`s sorting is disabled and the sorting mechanism of the collection is used instead.
Check out the chapters entirely dedicated to the sorting functionality of RadGridView and find the answers to the following questions:
What are the available types of sorting.
How does the basic sorting work.
How to define sorting using SortDescriptors in both XAML and code-behind.
How to use the exposed sort events.
How to disable the default sorting per column or for the whole RadGridView control.
How to define custom sorting based on the Sorting event.
How to sort your data by multiple-columns.
How to style the column header of the sorted column.