Spread Windows Forms 13.0 Product Documentation
FarPoint.Win.Spread Assembly / FarPoint.Win.Spread Namespace / SheetView Class / SortRange Method
Example


In This Topic
    SortRange Method
    In This Topic
    Sorts a range of cells on this sheet in the data model.
    Overload List
    OverloadDescription
    Sorts a range of cells on this sheet in the data model.  
    Remarks

    This 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 of moving the data around in the data source.

    If byRows is true, the range is sorted by rows; if byRows if false, the range is sorted by columns.

    With the sortInfo array, 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.

    For bound data, use the SortColumns or SortRows methods. For a discussion of sorting, refer to Managing Sorting of Rows.

    Example
    This example sorts a range of cells in the sheet.
    FarPoint.Win.Spread.SortInfo[] sort = new FarPoint.Win.Spread.SortInfo[1];
    sort[0] = new FarPoint.Win.Spread.SortInfo(0, true, System.Collections.Comparer.Default);
    fpSpread1.ActiveSheet.SetValue(0, 0, "C");
    fpSpread1.ActiveSheet.SetValue(1, 0, "A");
    fpSpread1.ActiveSheet.SetValue(2, 0, "E");
    fpSpread1.ActiveSheet.SetValue(3, 0, "B");
    fpSpread1.ActiveSheet.SetValue(0, 1, "3");
    fpSpread1.ActiveSheet.SetValue(1, 1, "5");
    fpSpread1.ActiveSheet.SetValue(2, 1, "1");
    fpSpread1.ActiveSheet.SetValue(3, 1, "2");
    fpSpread1.ActiveSheet.SortRange(0, 0, 4, 2, true, sort);
    Dim sort(1) As FarPoint.Win.Spread.SortInfo
    sort(0) = New FarPoint.Win.Spread.SortInfo(0, True, System.Collections.Comparer.Default)
    FpSpread1.ActiveSheet.SetValue(0, 0, "C")
    FpSpread1.ActiveSheet.SetValue(1, 0, "A")
    FpSpread1.ActiveSheet.SetValue(2, 0, "E")
    FpSpread1.ActiveSheet.SetValue(3, 0, "B")
    FpSpread1.ActiveSheet.SetValue(0, 1, "3")
    FpSpread1.ActiveSheet.SetValue(1, 1, "5")
    FpSpread1.ActiveSheet.SetValue(2, 1, "1")
    FpSpread1.ActiveSheet.SetValue(3, 1, "2")
    FpSpread1.ActiveSheet.SortRange(0, 0, 4, 2, True, sort)
    See Also