Version

Sort(SortOrder) Method

Sorts this collection by the value of the TextResolved property.
Syntax
'Declaration
 
Public Overloads Sub Sort( _
   ByVal sortOrder As SortOrder _
) 
public void Sort( 
   SortOrder sortOrder
)

Parameters

sortOrder
The SortOrder constant which determines whether the sort is ascending or descending.
Remarks

The Sort method of the NavigationBarLocationsCollection class causes the actual ordinal positions of the members of the collection to be changed. The Sort method of the NavigationBarLocationsCollection.VisibleLocationsCollection class (returned from the VisibleMembers property), by contrast, does not affect the ordinal positions of the members of the associated Locations collection.

Example
The following code sample demontrates how to use the UltraNavcigationBar's custom sorting capabilities:

Imports System
Imports System.Drawing
Imports System.IO
Imports System.Collections.Generic
Imports System.ComponentModel
Imports Infragistics.Shared
Imports Infragistics.Win
Imports Infragistics.Win.Misc
Imports Infragistics.Win.Misc.UltraWinNavigationBar

Public Class FileSystemSupport

    ' <summary>
    ' Sort the root's visible locations collection so that the
    ' shortcut(s) always appear at the top of the list, and all
    ' other locations are sorted by Text and not DisplayText (this
    ' keeps the system drives alphabetized based on the drive letter).
    ' </summary>
    ' <param name="navigationBar">The associated UltraNavigationBar.</param>
    ' <param name="sortVisibleMembers">Specifies whether to sort the VisibleLocationsCollection, or the actual Locations collection.</param>
    Private Sub SortRootLocationChildren(ByVal navigationBar As UltraNavigationBar, ByVal sortVisibleMembers As Boolean)

        '  Note that sorting the VisibleLocationsCollection (returned by the VisibleMembers
        '  property) does not change the ordinal positions of the locations within the Locations
        '  collection, it only changes the ordering within the visible list.
        If (sortVisibleMembers) Then
            navigationBar.RootLocation.Locations.VisibleMembers.Sort(New RootSortComparer())
        Else
            navigationBar.RootLocation.Locations.Sort(New RootSortComparer())
        End If
    End Sub

    '   Implements the IComparer interface for the purpose of sorting
    '   the immediate children of the root location
    Public Class RootSortComparer
        Implements IComparer(Of UltraNavigationBarLocation)

        Public Function Compare(ByVal x As Infragistics.Win.Misc.UltraNavigationBarLocation, ByVal y As Infragistics.Win.Misc.UltraNavigationBarLocation) As Integer Implements System.Collections.Generic.IComparer(Of Infragistics.Win.Misc.UltraNavigationBarLocation).Compare

            If x Is Nothing Or y Is Nothing Then Return 0

            Dim xIsShortcut As Boolean = False
            Dim yIsShortcut As Boolean = False
            Dim wrapper As DirectoryWrapper = Nothing

            '   Determine whether one or both is a shortcut; if both or neither are,
            '   they get sorted by the resolved value of the Text property (rather than
            '   DisplayText), so that the locations are sorted by their drive letter rather
            '   than the volume name. If one is a shortcut but the other is not, the shortcut
            '   should appear before.
            If Not x.Tag Is Nothing Then
                wrapper = x.Tag
                xIsShortcut = wrapper.GetType() Is GetType(ShortcutWrapper)
            End If

            If Not y.Tag Is Nothing Then
                wrapper = y.Tag
                yIsShortcut = wrapper.GetType() Is GetType(ShortcutWrapper)
            End If

            If (xIsShortcut = True AndAlso yIsShortcut = False) Then
                Return -1
            ElseIf (xIsShortcut = False AndAlso yIsShortcut = True) Then
                Return 1
            Else
                Return x.TextResolved.CompareTo(y.TextResolved)
            End If

        End Function
    End Class


End Class
using System;
using System.Drawing;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using Infragistics.Shared;
using Infragistics.Win;
using Infragistics.Win.Misc;
using Infragistics.Win.Misc.UltraWinNavigationBar;

    public class FileSystemSupport
    {

        /// <summary>
        /// Sort the root's visible locations collection so that the
        /// shortcut(s) always appear at the top of the list, and all
        /// other locations are sorted by Text and not DisplayText (this
        /// keeps the system drives alphabetized based on the drive letter).
        /// </summary>
        /// <param name="navigationBar">The associated UltraNavigationBar.</param>
        /// <param name="sortVisibleMembers">Specifies whether to sort the VisibleLocationsCollection, or the actual Locations collection.</param>
        private void SortRootLocationChildren( UltraNavigationBar navigationBar, bool sortVisibleMembers )
        {
            //  Note that sorting the VisibleLocationsCollection (returned by the VisibleMembers
            //  property) does not change the ordinal positions of the locations within the Locations
            //  collection, it only changes the ordering within the visible list.
            if ( sortVisibleMembers )
                navigationBar.RootLocation.Locations.VisibleMembers.Sort( new RootSortComparer() );
            else
                navigationBar.RootLocation.Locations.Sort( new RootSortComparer() );
        }

        public class RootSortComparer : IComparer<UltraNavigationBarLocation>
        {
            int IComparer<UltraNavigationBarLocation>.Compare(UltraNavigationBarLocation x, UltraNavigationBarLocation y)
            {
                if ( x == null || y == null )
                    return 0;

                //   Determine whether one or both is a shortcut; if both or neither are,
                //   they get sorted by the resolved value of the Text property (rather than
                //   DisplayText), so that the locations are sorted by their drive letter rather
                //   than the volume name. If one is a shortcut but the other is not, the shortcut
                //   should appear before.
                bool xIsShortcut = x.Tag is ShortcutWrapper;
                bool yIsShortcut = y.Tag is ShortcutWrapper;

                if ( xIsShortcut && yIsShortcut == false )
                    return -1;
                else
                if ( xIsShortcut == false && yIsShortcut )
                    return 1;
                else
                    return x.TextResolved.CompareTo(y.TextResolved);
            }

        }

    }
Requirements

Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Server 2012, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also