Friday, July 04, 2008  



 FarPoint Technologies
 (800) 645-5913

 fpsales@fpoint.com



     
 »Spread for Windows Forms » Product Tour » Managing Data » Sorting Data

Previous Sorting Data on a Sheet Next

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 various ways of performing a sort with various properties and methods for each type of sorting.

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). 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.

  Back to Top
 Sorting All Rows or Columns
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.

To sort rows, use the SortRows method; to sort columns, use the SortColumns method.

' Sorts all the rows in the sheet according to the values in the second column. The sort is in ascending order and the indicator is turned on.

fpSpread1.ActiveSheet.SortRows(1,true,true)


  Back to Top
 Sorting Data in a Range
You can sort data in a range of cells. 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.

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.

// Sorts rows 12 to 230 using a predefined array of sort information.
FarPoint.Win.Spread.SortInfo[] sorter = new FarPoint.Win.Spread.SortInfo[1];
sorter[0] = new FarPoint.Win.Spread.SortInfo(0, false, System.Collections.Comparer.Default);
fpSpread1.ActiveSheet.SortColumns(12,230,sorter);

' Sorts rows 12 to 230 using a predefined array of sort information.
Dim sorter(1) As FarPoint.Win.Spread.SortInfo
sorter(0) = New FarPoint.Win.Spread.SortInfo(0, False, System.Collections.Comparer.Default)
fpSpread1.ActiveSheet.SortColumns(12,230,sorter);


  Back to Top
 Performing Automatic Sorting
Use the AutoSortColumn method to perform the sorting and use the SetColumShowSortIndicator to set whether to show the sort indicator. The AutoSortColumn method performs the same action as clicking in the column header of the specified column that has its AllowAutoSort property set to True.

// Automatically sort the first column.
fpSpread1.ActiveSheet.SetColumnAllowAutoSort(0, true);
fpSpread1.ActiveSheet.SetColumnShowSortIndicator(0, false);
fpSpread1.ActiveSheet.AutoSortColumn(0);


' Automatically sort the first column.
fpSpread1.ActiveSheet.SetColumnAllowAutoSort(0, True)
fpSpread1.ActiveSheet.SetColumnShowSortIndicator(0, False)
fpSpread1.ActiveSheet.AutoSortColumn(0)


  Back to Top
 Allowing the User to Perform Automatic Sorting
You can set the spreadsheet to allow the user to automatically sort the data when a column header is clicked. If the user clicks successively on the same column, then the direction of the sort is reversed. This does not affect the data model, only how the data is displayed.

// Allow automatic sorting for the first 30 columns.
fpSpread1.Sheets[0].Columns[0,29].AllowAutoSort = true;

' Allow automatic sorting for the first 30 columns.
FpSpread1.Sheets(0).Columns(0,29).AllowAutoSort = True


Previous Sorting Data on a Sheet Next

    
 Have a question?
Have a Question? Ask Us!
Subscribe to the RSS feed!RSS Subscribe
 

 
SD Times 'TOP 100' Industry Innovator - Read the press release (pdf)

Tour Home
Overview
Appearance
User Interaction
Cell Types
Formulas
Managing Data
Data Binding
Import/Export
Printing
Keyboard Interaction
Shapes
Models
Spread Designer
 
Map

Copyright © 1991-2007 FarPoint Technologies, Inc. All rights reserved. All names are property of their respective owners.