Hide

SftTree/NET 2.0 - Tree Control for Windows Forms

Display
Print

Sort Method, ItemCollectionClass Class

Sorts the items in the item collection.

Class: ItemCollectionClass
Namespace: Softelvdm.SftTreeNET
Assembly: Softelvdm.SftTreeNET

Syntax

public void Sort();
public void Sort( IComparer Comparer );
public void Sort(
    IComparer Comparer,
    bool Recursive );
Public Sub Sort()
Public Sub Sort( ByVal Comparer As IComparer )
Public Sub Sort(
    ByVal Comparer As IComparer,
    ByVal Recursive As Boolean )

Parameters

Comparer

Defines a method that compares two items or null/Nothing to use the SortAscending class implementation.

Recursive

Defines whether the dependents are also sorted, True to sort all direct and indirect dependents also, otherwise False. The default is False.

Comments

Sorts the items in the item collection.

Comparer implements a method that is used to compare two items. The sorting process calls this method repeatedly to sort the item collection. The method can sort items based on any of their attributes, even multiple keys.

Default implementations are available to sort cell text in a column ascending (SortAscending) or descending (SortDescending). Samples, including the implementation of SortAscending and SortDescending are shown below.

Examples

C#

            if (e.Area != ItemClickAreaEnum.Cell)
                return;

            bool fAscending = SetSorted(e.Cell.ColumnIndex);

            switch (e.Cell.ColumnIndex) {
            default: // column 0 and 1 are sorted based on the Text property
                if (fAscending)
                    sftTree1.ItemCollection.Sort(new SortAscending(e.Cell.ColumnIndex));
                else
                    sftTree1.ItemCollection.Sort(new SortDescending(e.Cell.ColumnIndex));
                break;
            case 2: case 3: // column 2 and 3 are sorted based on the TagObject property, interpreted as a long
                if (fAscending)
                    sftTree1.ItemCollection.Sort(new SortTagObjectAsLongAscending(e.Cell.ColumnIndex));
                else

VB.NET

        Return
    End If

    Dim fAscending As Boolean = SetSorted(e.Cell.ColumnIndex)

    Select Case e.Cell.ColumnIndex
    Case 2, 3 ' column 2 and 3 are sorted based on the TagObject property, interpreted as a long
        If fAscending Then
            sftTree1.ItemCollection.Sort(New SortTagObjectAsLongAscending(e.Cell.ColumnIndex))
        Else
            sftTree1.ItemCollection.Sort(New SortTagObjectAsLongDescending(e.Cell.ColumnIndex))
        End If
    Case Else ' column 0 and 1 are sorted based on the Text property
        If fAscending Then
            sftTree1.ItemCollection.Sort(New SortAscending(e.Cell.ColumnIndex))
        Else

See Also ItemCollectionClass Class | Classes | SftTree/NET 2.0



Spring Break!

Our offices will be closed this week (March 18 through March 22).

We'll be back March 24 to address any pending sales and support issues.