Spread Windows Forms 8.0 Product Documentation > Developer's Guide > Customizing Row or Column Interaction > Managing Sorting of Rows of User Data > Sorting Rows, Columns, or Ranges |
You can sort entire rows or columns in a sheet. To sort all the rows of an entire sheet based on the values of a given column is the most common case, but Spread allows you to sort either rows or columns and to specify which column or row to use as a key for sorting. The sort applies to the entire sheet.
Use the SortColumns (or SortRows) method to sort the arrangement of columns (or rows) in a sheet using one or more rows (or columns) as the key. This does not affect the data model, only how the data is displayed. Several overloads provide different ways to sort the columns (or rows). To further customize the way sorting is performed, use the SortInfo object in conjunction with these methods.
You can sort data in a range of cells without arranging the entire row or column in a sheet. This may be useful when, for example, you wish to arrange many rows in order of quantity but not include in the sort the final row that contains the totals of those quantities. In this case, you would sort the data in a range of cells but leave at least the final row, the bottom line, unsorted.
There are two ways to sort data in a range. For bound data, use the SortRows and SortColumns methods using the specified parameters in the overloads to specify which range of rows or columns to sort. For unbound data, simply use the SortRange method. For more information on sorting using the Spread Designer at design time, refer to the Using the Spread Designer procedure below.
The SortRange method is for unbound data only. This method sorts the data in a range of cells by moving the data around in the data model and moving the cell-level styles along with it. This method is not intended for bound data, as it moves data (not necessarily by entire row or column) and has the effect of moving the data around in the data source.
With the sortInfo array of the SortRange method, you can specify multiple criteria for sorting the data. This method gives you the ability to sort (or arrange) data in a smaller subset than entire rows or columns in a sheet. For more information, refer to the SortInfo object.
To sort rows, use the SortRows method; to sort columns, use the SortColumns method.
This example sorts all the rows in the sheet according to the values in the second column. (Since column index is zero-based, the second column is 1.) The sort indicator is turned on.
C# |
Copy Code
|
---|---|
fpoint1.ActiveSheet.SortRows(1,true,true); |
VB |
Copy Code
|
---|---|
Fpoint1.ActiveSheet.SortRows(1,True,True) |
To sort rows, use the SortRows method; to sort columns, use the SortColumns method.
This example sorts rows 12 to 230 using a predefined array of sort information.
C# |
Copy Code
|
---|---|
FarPoint.Win.Spread.SortInfo[] sorter = new FarPoint.Win.Spread.SortInfo[1]; sorter[0] = new FarPoint.Win.Spread.SortInfo(0, false, System.Collections.Comparer.Default); fpoint1.ActiveSheet.SortColumns(12,230,sorter); |
VB |
Copy Code
|
---|---|
Dim sorter(1) As FarPoint.Win.Spread.SortInfo sorter(0) = New FarPoint.Win.Spread.SortInfo(0, False, System.Collections.Comparer.Default) fpoint1.ActiveSheet.SortColumns(12,230,sorter); |