GemBox.Spreadsheet
  • Overview
  • Examples
  • Free version
  • Support
  • Pricelist

    Show / Hide Table of Contents

    SortState Class

    Namespace:
    GemBox.Spreadsheet
    Assembly:
    GemBox.Spreadsheet.dll

    Represents sort settings and provides sort functionality.

    • C#
    • VB.NET
    public sealed class SortState
    Public NotInheritable Class SortState
    Inheritance:
    System.Object
    SortState
    Remarks

    Use Sort(Boolean) method to create or get a SortState instance.

    Active SortState is stored in the parent worksheet (Sort) and is loaded from and saved to XLSX file.

    Properties

    CaseSensitive

    Gets or sets a value indicating whether the sort is case-sensitive.

    Default value is false.

    • C#
    • VB.NET
    public bool CaseSensitive { get; set; }
    Public Property CaseSensitive As Boolean
    Property Value
    System.Boolean

    true if the sort is case-sensitive; otherwise, false.

    LeftToRight

    Gets or sets a value indicating whether to sort from left to right (whether to sort columns instead of rows).

    Default value is false.

    • C#
    • VB.NET
    public bool LeftToRight { get; set; }
    Public Property LeftToRight As Boolean
    Property Value
    System.Boolean

    true to sort from left to right (to sort columns); otherwise, false to sort from top to bottom (to sort rows).

    Exceptions
    System.InvalidOperationException

    Sorting columns is not supported for the current sort state.

    Levels

    Gets the sort levels.

    • C#
    • VB.NET
    public SortLevelCollection Levels { get; }
    Public ReadOnly Property Levels As SortLevelCollection
    Property Value
    SortLevelCollection

    The sort levels.

    Range

    Gets the range to sort.

    • C#
    • VB.NET
    public CellRange Range { get; }
    Public ReadOnly Property Range As CellRange
    Property Value
    CellRange

    The range to sort.

    Methods

    Apply()

    Performs the sorting of this Range based on this SortState settings.

    • C#
    • VB.NET
    public void Apply()
    Public Sub Apply
    Remarks

    Hidden (Hidden is true) rows (or columns, if LeftToRight is true) won't be sorted.

    Exceptions
    System.InvalidOperationException

    Sort range contains merged cells.

    By(Int32)

    Adds a SortLevel applied to a column (or a row, if LeftToRight is true) with the specified index (relative to the Range).

    • C#
    • VB.NET
    public SortState By(int columnRowIndex)
    Public Function By(columnRowIndex As Integer) As SortState
    Parameters
    columnRowIndex
    System.Int32

    The index of a column (or a row, if LeftToRight is true) relative to the Range that an added SortLevel applies to.

    Returns
    SortState

    This SortState to specify additional sort levels or to apply sort.

    Exceptions
    System.ArgumentOutOfRangeException

    columnRowIndex is less than zero or is equal to or greater than Width (or Height, if LeftToRight is true) of the Range.

    System.ArgumentException

    Column/row at the specified index is being sorted by the same criteria more than once. Delete the duplicate sort criteria and try again.

    By(Int32, Boolean)

    Adds a SortLevel applied to a column (or a row, if LeftToRight is true) with the specified index (relative to the Range) and with the specified order to sort by.

    • C#
    • VB.NET
    public SortState By(int columnRowIndex, bool descending)
    Public Function By(columnRowIndex As Integer, descending As Boolean) As SortState
    Parameters
    columnRowIndex
    System.Int32

    The index of a column (or a row, if LeftToRight is true) relative to the Range that an added SortLevel applies to.

    descending
    System.Boolean

    true to sort the values in the descending order; otherwise, false.

    Returns
    SortState

    This SortState to specify additional sort levels or to apply sort.

    Exceptions
    System.ArgumentOutOfRangeException

    columnRowIndex is less than zero or is equal to or greater than Width (or Height, if LeftToRight is true) of the Range.

    System.ArgumentException

    Column/row at the specified index is being sorted by the same criteria more than once. Delete the duplicate sort criteria and try again.

    By(Int32, Boolean, IEnumerable<String>)

    Adds a SortLevel applied to a column (or a row, if LeftToRight is true) with the specified index (relative to the Range) and with the specified order and custom list by which order of items to sort by.

    • C#
    • VB.NET
    public SortState By(int columnRowIndex, bool descending, IEnumerable<string> customList)
    Public Function By(columnRowIndex As Integer, descending As Boolean, customList As IEnumerable(Of String)) As SortState
    Parameters
    columnRowIndex
    System.Int32

    The index of a column (or a row, if LeftToRight is true) relative to the Range that an added SortLevel applies to.

    descending
    System.Boolean

    true to sort the values in the descending order; otherwise, false.

    customList
    System.Collections.Generic.IEnumerable<System.String>

    The custom list by which order of items to sort by.

    Returns
    SortState

    This SortState to specify additional sort levels or to apply sort.

    Exceptions
    System.ArgumentOutOfRangeException

    columnRowIndex is less than zero or is equal to or greater than Width (or Height, if LeftToRight is true) of the Range.

    System.ArgumentException

    Column/row at the specified index is being sorted by the same criteria more than once. Delete the duplicate sort criteria and try again.

    By(Int32, Boolean, String[])

    Adds a SortLevel applied to a column (or a row, if LeftToRight is true) with the specified index (relative to the Range) and with the specified order and custom list by which order of items to sort by.

    • C#
    • VB.NET
    public SortState By(int columnRowIndex, bool descending, params string[] customList)
    Public Function By(columnRowIndex As Integer, descending As Boolean, ParamArray customList As String()) As SortState
    Parameters
    columnRowIndex
    System.Int32

    The index of a column (or a row, if LeftToRight is true) relative to the Range that an added SortLevel applies to.

    descending
    System.Boolean

    true to sort the values in the descending order; otherwise, false.

    customList
    System.String[]

    The custom list by which order of items to sort by.

    Returns
    SortState

    This SortState to specify additional sort levels or to apply sort.

    Exceptions
    System.ArgumentOutOfRangeException

    columnRowIndex is less than zero or is equal to or greater than Width (or Height, if LeftToRight is true) of the Range.

    System.ArgumentException

    Column/row at the specified index is being sorted by the same criteria more than once. Delete the duplicate sort criteria and try again.

    By(Int32, IEnumerable<String>)

    Adds a SortLevel applied to a column (or a row, if LeftToRight is true) with the specified index (relative to the Range) and with the specified custom list by which order of items to sort by.

    • C#
    • VB.NET
    public SortState By(int columnRowIndex, IEnumerable<string> customList)
    Public Function By(columnRowIndex As Integer, customList As IEnumerable(Of String)) As SortState
    Parameters
    columnRowIndex
    System.Int32

    The index of a column (or a row, if LeftToRight is true) relative to the Range that an added SortLevel applies to.

    customList
    System.Collections.Generic.IEnumerable<System.String>

    The custom list by which order of items to sort by.

    Returns
    SortState

    This SortState to specify additional sort levels or to apply sort.

    Exceptions
    System.ArgumentOutOfRangeException

    columnRowIndex is less than zero or is equal to or greater than Width (or Height, if LeftToRight is true) of the Range.

    System.ArgumentException

    Column/row at the specified index is being sorted by the same criteria more than once. Delete the duplicate sort criteria and try again.

    By(Int32, Comparison<ExcelCell>)

    Adds a SortLevel applied to a column (or a row, if LeftToRight is true) with the specified index (relative to the Range) and with the specified comparison method to sort by.

    • C#
    • VB.NET
    public SortState By(int columnRowIndex, Comparison<ExcelCell> comparison)
    Public Function By(columnRowIndex As Integer, comparison As Comparison(Of ExcelCell)) As SortState
    Parameters
    columnRowIndex
    System.Int32

    The index of a column (or a row, if LeftToRight is true) relative to the Range that an added SortLevel applies to.

    comparison
    System.Comparison<ExcelCell>

    The comparison method to sort by.

    Returns
    SortState

    This SortState to specify additional sort levels or to apply sort.

    Exceptions
    System.ArgumentOutOfRangeException

    columnRowIndex is less than zero or is equal to or greater than Width (or Height, if LeftToRight is true) of the Range.

    System.ArgumentException

    Column/row at the specified index is being sorted by the same criteria more than once. Delete the duplicate sort criteria and try again.

    By(Int32, String[])

    Adds a SortLevel applied to a column (or a row, if LeftToRight is true) with the specified index (relative to the Range) and with the specified custom list by which order of items to sort by.

    • C#
    • VB.NET
    public SortState By(int columnRowIndex, params string[] customList)
    Public Function By(columnRowIndex As Integer, ParamArray customList As String()) As SortState
    Parameters
    columnRowIndex
    System.Int32

    The index of a column (or a row, if LeftToRight is true) relative to the Range that an added SortLevel applies to.

    customList
    System.String[]

    The custom list by which order of items to sort by.

    Returns
    SortState

    This SortState to specify additional sort levels or to apply sort.

    Exceptions
    System.ArgumentOutOfRangeException

    columnRowIndex is less than zero or is equal to or greater than Width (or Height, if LeftToRight is true) of the Range.

    System.ArgumentException

    Column/row at the specified index is being sorted by the same criteria more than once. Delete the duplicate sort criteria and try again.

    ToString()

    Returns a System.String that represents this SortState instance.

    • C#
    • VB.NET
    public override string ToString()
    Public Overrides Function ToString As String
    Returns
    System.String

    A System.String that represents this SortState instance.

    Overrides
    System.Object.ToString()
    Remarks

    This method should be used primarily for debugging purposes and should be considered volatile (format of its return value might change in future versions).

    Examples

    Excel Sorting example
    Back to top

    Facebook • Twitter • LinkedIn

    © GemBox Ltd. — All rights reserved.