$99 VS $1000+. UI Control for ASP.NET AJAX(contains chart and gridview).
GridView Control for Windows Forms
Set data sorting in grid by using DataGridView component in Windows Forms applications
Home > WinForms UI Controls > User Manual > Setting to Grid Sorting in C#

GridView Data Sorting in C#

The Kettic GridView .NET component provides a SortDescriptors property for users to set the grid data sorting function. This property is at the level of GridViewTemplate that is exposed in KetticGridView C# class for MasterTemplate instance. The descriptors for sorting allow users to create grid data sorting property and grid data sorting direction. The descriptor is a collection so that users just need perform the delete or clear operation. The collection is able to sort grid data of the descriptor that has been newly added.

How to Create Data Sorting to GridView

The sorting functionality can be enabled through the SortDescriptor property. We need change the value of the EnableSorting property of the desired template to True. The simple C# code below demonstrates how to achieve this.

this.ketticGridView1.MasterTemplate.EnableSorting = true;
And then, we can create and add new SortDescriptor to the collection to create grid data sorting for GridView. In the C# code below, we are going to use the PropertyName and the SortDirection properties. The PropertyName property will determine the sorting of grid data and the SortDirection property will control the sort direction.

SortDescriptor descriptor = new SortDescriptor();
descriptor.PropertyName = "Products";
descriptor.Direction = ListSortDirection.Ascending;
this.ketticGridView1.MasterTemplate.SortDescriptors.Add(descriptor);

How to Sort Grid Data by Multiple Columns

The Kettic DataGridView component is capable of sorting grid data not only by one column, but also multiple columns. The C# code below shows how to sort grid data by two columns to GridView. In the example below, the GridView will sort the ProductName column first as this sort expressions are added first, and then sort all groups based on the Price.

SortDescriptor descriptorShipName = new SortDescriptor();
descriptorShipName.PropertyName = "ProductName";
descriptorShipName.Direction = ListSortDirection.Descending;
SortDescriptor descriptorFreight = new SortDescriptor();
descriptorFreight.PropertyName = "Price";
descriptorFreight.Direction = ListSortDirection.Descending;
this.ketticGridView1.SortDescriptors.Add(descriptorShipName);
this.ketticGridView1.SortDescriptors.Add(descriptorFreight);
UI Controlsfor Windows Forms
.NET WinForms UI Overview.NET WinForms UI Features.NET WinForms UI GuideC# WinForms UI DesignVB.NET WinForms UI Design
WinForms UI Controls