[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications, and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Collapse]Data Grid
   [Expand]Get Started With Data Grid and Views
   [Expand]Data Binding
    Unbound Columns
   [Expand]Views
   [Expand]Data Editing and Validation
   [Expand]Grouping
   [Collapse]Sorting
     Sorting in Code
   [Expand]Filter and Search
   [Expand]Summaries
   [Expand]Focus and Selection Handling
    Format Cell Values
   [Expand]Master-Detail Relationships
   [Expand]Asynchronous Image Load
   [Expand]Export and Printing
   [Expand]Appearance and Conditional Formatting
    Split Presentation
    Row Preview Sections
   [Expand]Scrolling
   [Expand]Batch Modifications
    Hit Information
    Hints
    Popup Menus
   [Expand]Save and Restore Layout
   [Expand]Visual Elements
   [Expand]Design-Time Features
   [Expand]Examples
   [Expand]End-User Capabilities
    Included Components
  [Expand]Vertical Grid
  [Expand]Property Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Diagrams
  [Expand]Gauges
  [Expand]Map Control
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]Printing-Exporting
  [Expand]PDF Viewer
   Reporting
  [Expand]Snap
  [Expand]TreeMap Control
  [Expand]Sunburst Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Sorting in Code

Expanded Sort and Unsort Data

GridColumn.SortOrder

Allows you to sort data by selecting between Ascending and Descending values. Setting this property to None removes sorting by this column.

ColumnView.SortInfo

A collection that stores specific ColumnSortInfo objects for every grid column involved in sorting and grouping. To sort data by specific columns, modify this collection manually by calling the GridColumnSortInfoCollection.ClearAndAddRange method. The code below illustrates two different approaches to sort Grid data ascending by order dates, and then descending by customer IDs.

ColumnView.BeginSort, ColumnView.EndSort

If you perform multiple sorting operations in code, wrap these code blocks between the BeginSort/EndSort method calls to prevent excessive redraw.

ColumnView.StartSorting, ColumnView.EndSorting

Non-cancelable events that fire when a sorting operation starts and after it is complete.

ColumnView.ClearSorting

Removes all currently applied data sorting.

Expanded Custom Sorting

The ColumnView.CustomColumnSort event fires when the Data Grid needs to sort data by a column, whose GridColumn.SortMode property equals Custom. The event allows you to compare rows one-by-one and decide what row should go first. In the example below, the default DateTime column sorting (comparing years, then months and dates) is changed to custom sorting where dates are compared by months and then days, while years are ignored.

Expanded See Also

Is this topic helpful?​​​​​​​