Spread Windows Forms 18
Spread Windows Forms 18 Product Documentation / Developer's Guide / Customizing Row or Column Interaction / Managing Sorting of Rows of User Data / Managing Cell Range Sorting
In This Topic
    Managing Cell Range Sorting
    In This Topic

    Spread for WinForms allows users to manage range sorting operations without any hassle via applying sort logic on a specific cell range in a worksheet. This makes it easier and quicker to manipulate data and arrange records based on a specific sort order while working with bulk data in spreadsheets.

    You can sort textual information in alphabetical order (like A-Z or Z-A), arrange numbers in ascending and descending order, sort dates from newest to oldest and vice a versa and order data based on the colors and icons in a cell range. 

    Users can work with cell range sorting in the following two ways:

    1. Using Sort Object of AutoFilter
    2. Using Sort Object in Worksheet

    Using Sort Object of AutoFilter

    You can apply sort logic on the data in a cell range using the Apply method of the ISort interface and the Add method of the ISortFields interface.

    Example

    Refer to the following example code in order to apply sort logic on a range of cells in a spreadsheet.

    C#
    Copy Code
    // Gets the sort column
    ISort filterSort = activeSheet.AutoFilter.Sort;
    
    // Sort column C by ascending order. 
    filterSort.SortFields.Add(1);
    
    // Set Sort Order for column B by descending
    filterSort.SortFields.Add(0).Order = GrapeCity.Spreadsheet.SortOrder.Descending;
    filterSort.Apply();
    
    VB
    Copy Code
    'Gets the sort column
    Dim filterSort As ISort = activeSheet.AutoFilter.Sort
    
    'Sort column C by ascending order
    filterSort.SortFields.Add(1)
    
    'Set Sort Order for column B by descending
    filterSort.SortFields.Add(0).Order = GrapeCity.Spreadsheet.SortOrder.Descending
    filterSort.Apply()
    

    Using Sort Object in Worksheet

    You can add and apply sort logic on a cell range using the Add method of the ISortFields interface and the Apply method.

    Using Code

    In order to apply the sort logic in a cell range using the sort object of the worksheet, you can use the Apply method of the ISort interface.

    Example

    Refer to the following example code to access the current filter settings in a worksheet.

    C#
    Copy Code
    // Sort column C
    worksheetSort.SortFields.Add("C1")         
    // Sort range is B1:E10
    worksheetSort.SetRange("B1:E10");
    worksheetSort.Apply();
    

    VB
    Copy Code
    'Sort column C  
    worksheetSort.SortFields.Add("C1")
    
    'Sort range is B1:E10
    worksheetSort.SetRange("B1:E10")
    worksheetSort.Apply()
    
    See Also