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 DesignWinForms UI Controls WinForms Buttons UI Control WinForms Calendar UI ControlWinForms Carousel UI ControlWinForms Chart UI ControlWinForms Clock UI ControlCommandBar UI ControlWinForms Dock UI ControlDesktop Alert UI ControlDropDown List UI ControlWinForms Editor UI ControlForms and Dialogs UI ControlWinForms GridView UI ControlGridView - Get Started in C#GridView - PropertiesGridView - ColumnGridView - RowGridView - CellsGridView - EditorsGridView - Context MenuGridView - Populating with DataGridView - Hierarchical GridData Binding AutomaticallyData Binding ProgrammaticallyXML Data SourceResize Child GridVieInfoOne to Many RelationsExpand RowsGridView - SelectionBasic SelectionMultiple SelectionProgrammatical Rows & Cells Selection GridView - ScrollingGridView - SortingSet ProgrammaticallySorting ExpressionsGridView - GroupingGridView - FilteringGridView - Expression EditorInsert/ Update/ Delete RecordsGridView - View DefinitionGridView - Exporting DataStyling and AppearanceGridView - LocalizationSave and Load LayoutGridView - Print SupportWinForms ListView UI ControlWinForms Menu UI ControlWinForms ComboBox UI ControlWinForms PageView UI ControlPanels and Labels UI ControlWinForms Panorama UI ControlWinForms PDFViewer UI ControlWinForms Property Grid UI ControlWinForms Ribbon UI ControlWinForms PivotGrid UI ControlWinForms RichTextBox UI ControlWinForms Rotator UI ControlWinForms Scheduler UI ControlWinForms Shortcuts UI ControlWinForms SpellChecker UI ControlWinForms Track & Status UI ControlWinForms TreeView UI ControlWinForms Wizard UI ControlWinForms Test UI ControlWinForms Theme UI Control |