Spread Windows Forms 17
Spread Windows Forms 17.0 Product Documentation / Developer's Guide / Customizing Row or Column Interaction / Managing Sorting of Rows of User Data / Using Automatic Sorting
In This Topic
    Using Automatic Sorting
    In This Topic

    You can sort entire rows or columns automatically in a sheet. The component automatically sorts the rows in a sheet according to the specified column in ascending order unless the sheet was previously automatically sorted ascending. The automatic sorting displays the sort indicator unless the sort indicator for the column has been disabled. This does not affect the data model, only how the data is displayed. Different overloads provide different ways to perform the sorting.

    Use the AutoSortColumn method to sort the display in a sheet automatically according to the specified key and use the SetColumShowSortIndicator to set whether to display 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. The AllowAutoSort property does not need to be set to True to use this method. If this method is called successively with the same column index, then the direction of the sort is reversed. If the method is called with a different column index, then the previously sorted column's sort indicator is changed back to SortIndicator.None (if there is one) and the specified column is used as the key column in a call to SortRows to sort all the rows in the sheet by that column. This affects only the arrangement of rows or columns on a sheet and does not change the arrangement of the data; that is, this does not affect the data model, only how the data is displayed.

    Note: The SetColumShowSortIndicator method must be called before the AutoSortColumn method; otherwise, the sort indicator is shown and remains displayed.

    Using Code

    1. Allow the automatic sorting of a column or columns by using the SetColumnAllowAutoSort method.
    2. If you want to display a sort indicator, set the column to show the sort indicator with the SetColumnShowSortIndicator method.
    3. Perform the automatic sort by setting the AutoSortColumn method.

    Example

    This example automatically sorts the first column.

    C#
    Copy Code
    fpSpread1.ActiveSheet.SetColumnAllowAutoSort(0, true);
    fpSpread1.ActiveSheet.SetColumnShowSortIndicator(0, false);
    fpSpread1.ActiveSheet.AutoSortColumn(0); 
    
    VB
    Copy Code
    fpSpread1.ActiveSheet.SetColumnAllowAutoSort(0, True)
    FpSpread1.ActiveSheet.SetColumnShowSortIndicator(0, False)
    FpSpread1.ActiveSheet.AutoSortColumn(0)
    
    See Also