- Online Barcode Generator
- How To
- Buy Now
Custom Sorting in GridView
The Kettic GridView component is able to create custom sorting of grid data. This flexible sorting allows users to sort rows data that is bound to GridView according to custom logic. To create custom sorting to grid data, we need enable the GridView.EnableSorting property or the GridViewTemplate.EnableSorting property. When enabling the sorting property, the GridView will sort data at all levels. There are two approaches available for users to customize sorting to GridView, handling the CustomizeSorting event and applying a custom SortComparer to replace the Kettic GridView sorting.
How to Create Custom Sorting to GridView
When we enable the GridView.EnableSorting property or the GridViewTemplate.EnableSorting property, the CustomSorting event is fired. This custom sorting event contains several properties, such as Template, Row1, Row2, SortResult, and Handled. The following are the explanation of these properties.
C# code for Creating Custom Sorting
The C# code below shows how to handle the CustomSorting event to perform the ascending grid data sorting based on the Price column in GridView rows.
The C# code below shows how to use the Handled property of the CustomSorting event arguments. In this case, we are going to uses custom sorting to sort the grid data rows descending according to the Price column values.
Implement Data Sorting using SortComparer in C#.NET
To implement data sorting by using the SortComparer in C#.NET project, we need use a custom sorting to replace the default one. This is accomplished through setting the SortComparer of the GridViewTemplate. The C# code below shows how to sort the grid data rows ascending according to the name of the Product by a custom sorting logic.
The following example demonstrates how to use a custom sorting mechanism in KetticGridView to sort the KetticGridView rows Descending by the length of the ShipCity column:
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