Spread Windows Forms 10.0 Product Documentation > Developer's Guide > Customizing Row or Column Interaction > Managing Sorting of Rows of User Data |
You can sort the data displayed in the sheet either by column or by row. Typically, all the rows of a sheet are sorted by the values in a particular column. But Spread allows many ways of performing a sort with various properties and methods for each type of sorting. In general, sorting data can be performed and customized by any of the following ways:
There are various properties of sorting. The order of the sort can be in ascending order (A to Z, zero to 9) or descending order (Z to A, 9 to zero). The method of comparison can be customized. You can select which values to use as a key when comparing in order to sort the values. The sort indicator, an arrow typically, can be displayed in the header for the column being used as a sort key. For more information on customizing the sorting, refer to the SortInfo object. With this object, you can set the parameters for sorting and then specify this object in the particular sort method you choose.
The cell type does not matter for sorting. The sorting is done depending on the data type of the values in the cells. If you sort cells with data of the DateTime type, then it sorts those cells by date, and if you sort cells with data of the string type, it sorts those cells alphabetically.
Be aware of how sorting works with the data in the models. If you use the automatic sorting by clicking the column header or you call the SortRows method of the sheet, then the data model is not sorted, just the data that is displayed to the user. In this case, any data that is hidden before the sort is hidden after the sort, since Spread moves any hidden rows automatically. If you use the SortRange method, the data is sorted in the data model and data that is hidden may become visible and vice versa using this method. When you sort data, only the data model is getting sorted. The selection model does not get sorted. If you want the selected row to move, you would need to write code in the AutoSortedColumn and AutoSortingColumn events to move the selection. For more information on the models, refer to Understanding the Underlying Models.
Sorting performed by clicking column headers sorts only the displayed data and does not affect the order of actual data in the data model; therefore, you can reset the sorted data being displayed to the order of actual data by calling either the ResetViewRowIndexes method or the ResetViewColumnIndexes method in the SheetView.DocumentModels class. You cannot reset the result when the actual data in the data model are sorted with the SortRange method in the SheetView class.
Sorting is not intended to be used when Outlook-style grouping is turned on. For more information about grouping (which is a type of sorting), refer to Managing Grouping of Rows of User Data.
For information on sorting within the Spread Designer, refer to the Spread Designer Guide.
Note: Cell spans become invisible when sorting a sheet with any method except SortRange. |