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

Setting Sorting Programmatically

RadVirtualGrid includes SortDescriptors property. This collection allows you to use descriptors which define the sorting property and the sorting direction.

Before proceeding with this article, please refer to the Sorting Overview article which demonstrates how to fill data in RadVirtualGrid.

Here is how to create and add two SortDescriptors. The PropertyName property defines the property, by which the data will be sorted, and the SortDirection property allows you to define the sort direction.

WinForms RadVirtualGrid Setting Sorting Programmatically

Using SortDescriptor

SortDescriptor descriptorContactTitle = new SortDescriptor();
descriptorContactTitle.PropertyName = "ContactTitle";
descriptorContactTitle.Direction = ListSortDirection.Ascending;
SortDescriptor descriptorContactName = new SortDescriptor();
descriptorContactName.PropertyName = "ContactName";
descriptorContactName.Direction = ListSortDirection.Descending;
this.radVirtualGrid1.SortDescriptors.Add(descriptorContactTitle);
this.radVirtualGrid1.SortDescriptors.Add(descriptorContactName);

Dim descriptorContactTitle As New SortDescriptor()
descriptorContactTitle.PropertyName = "ContactTitle"
descriptorContactTitle.Direction = ListSortDirection.Ascending
Dim descriptorContactName As New SortDescriptor()
descriptorContactName.PropertyName = "ContactName"
descriptorContactName.Direction = ListSortDirection.Descending
Me.RadVirtualGrid1.SortDescriptors.Add(descriptorContactTitle)
Me.RadVirtualGrid1.SortDescriptors.Add(descriptorContactName)

The RadVirtualGrid.AllowMultiColumnSorting property should be set to true in order to achieve multiple columns sorting. Otherwise, RadVirtualGrid will be sorted by a single column.

See Also

In this article