Infragistics(R) NetAdvantage(R) Windows Forms
RootLocation Property
See Also  Example E-mail your feedback on this topic.
Infragistics.Win.Misc Namespace > UltraNavigationBar Class : RootLocation Property

Returns an UltraNavigationBarLocation-derived instance which represents the origin of the navigation path, i.e., the location that is the highest-level ancestor of all locations associated with this UltraNavigationBar.

Syntax

Visual Basic (Declaration) 
Public ReadOnly Property RootLocation As UltraNavigationBarRootLocation
C# 
public UltraNavigationBarRootLocation RootLocation {get;}

Example

The following code sample demonstrates how to populate an UltraNavigationBar control and an UltraTree control with the contents of the local machine's file system:

Visual BasicCopy Code
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
Imports Infragistics.Win.UltraWinTree

	Public Class FileSystemSupport
    	Private Const PATH_SEPARATOR As String = "\"
    	Private navigationBar As UltraNavigationBar = Nothing
    	Private tree As UltraTree = Nothing

    Public Sub Populate()

        '  Set up the root location to represent the 'Computer' location.
        Dim rootLocation As UltraNavigationBarLocation = Me.navigationBar.RootLocation

        '  Remove any existing members from the root's Locations collection.
        If (rootLocation.HasLocations) Then rootLocation.Locations.Clear()

        '  Clear the tree's Nodes collection and add the root node.
        Me.tree.Nodes.Clear()
        Dim rootNode As UltraTreeNode = Me.tree.Nodes.Add("Computer", "Computer")

        '  Set the Text for the root location and root node
        rootLocation.Text = rootNode.Text

        '  Note that we set the IncludeTextInFullPath property to false
        '  so that directory paths can be parsed without the end user
        '  having to type the name of the root. This will also prevent
        '  the text from appearing when the control is in edit mode.
        rootLocation.IncludeTextInFullPath = False

        '  Add the logical drives of this local machine to the root's Locations/Nodes collections.
        Dim locations As NavigationBarLocationsCollection = rootLocation.Locations
        Dim nodes As TreeNodesCollection = rootNode.Nodes

        '  Assign the appropriate image to the root location/node
        rootLocation.Settings.Appearance.Image = Me.GetImage(Images.Computer)
        rootNode.Override.NodeAppearance.Image = Me.GetImage(Images.Computer)

        Dim drives() As DriveInfo = DriveInfo.GetDrives()
        Dim i As Integer
        For i = 0 To drives.Length - 1

            Dim drive As DriveInfo = drives(i)

            '  Skip the drives we don't want to present to the end user.
            If (drive.DriveType = DriveType.Ram Or drive.DriveType = DriveType.NoRootDirectory Or drive.IsReady = False) Then
                Continue For
            End If

            '  Get the name of the drive, and remove the path separator.
            '  Also, get the volume name and use 'Local Disk' if none is assigned.
            Dim driveName As String = drive.Name
            driveName = driveName.Replace(PATH_SEPARATOR, String.Empty)
            Dim volumeLabel As String = drive.VolumeLabel
            volumeLabel = iif(Not volumeLabel Is Nothing AndAlso volumeLabel.Length > 0, volumeLabel, "Local Disk")

            '  Create a new UltraNavigationBarLocation instance, using the drive's name
            '  as the key, and the volume label/drive name as the DisplayText.
            Dim location As UltraNavigationBarLocation = New UltraNavigationBarLocation(driveName, driveName)

            '  Use the DisplayText property to format the combination of the drive letter
            '  and volume name so that we present it to the end user in a readable form.
            location.DisplayText = String.Format("{0} ({1})", volumeLabel, driveName)

            '  Add the location to the root's Locations collection.
            locations.Add(location)

            '  Add an accompanying tree node for the location we just added
            Dim node As UltraTreeNode = rootNode.Nodes.Add(location.Key, location.DisplayTextResolved)

            '  Assign the appropriate image to the location/node
            location.Settings.Appearance.Image = Me.GetImage(drive.DriveType)
            node.Override.NodeAppearance.Image = Me.GetImage(drive.DriveType)

            '  Assign an instance of a wrapper class which associates the node,
            '  location and directory to each object to the Tag property.
            node.Tag = New DirectoryWrapper(drive.RootDirectory, location)
            location.Tag = New DirectoryWrapper(drive.RootDirectory, node)
        Next

    End Sub

	End Class
C#Copy Code
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;
using Infragistics.Win.UltraWinTree;

    public class FileSystemSupport
    {
        private static readonly string PATH_SEPARATOR = "\\";
        private UltraNavigationBar navigationBar = null;
        private UltraTree tree = null;

        public void Populate()
        {
            try
            {
                System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;

                //  Set up the root location to represent the 'Computer' location.
                UltraNavigationBarLocation rootLocation = this.navigationBar.RootLocation;
                
                //  Remove any existing members from the root's Locations collection.
                if ( rootLocation.HasLocations )
                    rootLocation.Locations.Clear();

                //  Clear the tree's Nodes collection and add the root node.
                this.tree.Nodes.Clear();
                UltraTreeNode rootNode = this.tree.Nodes.Add( "Computer", "Computer" );

                //  Set the Text for the root location and root node
                rootLocation.Text = rootNode.Text;

                //  Note that we set the IncludeTextInFullPath property to false
                //  so that directory paths can be parsed without the end user
                //  having to type the name of the root. This will also prevent
                //  the text from appearing when the control is in edit mode.
                rootLocation.IncludeTextInFullPath = false;
                
                //  Add the logical drives of this local machine to the root's Locations/Nodes collections.
                NavigationBarLocationsCollection locations = rootLocation.Locations;
                TreeNodesCollection nodes = rootNode.Nodes;

                //  Assign the appropriate image to the root location/node
                rootLocation.Settings.Appearance.Image = this.GetImage(Images.Computer);
                rootNode.Override.NodeAppearance.Image = this.GetImage(Images.Computer);

                DriveInfo[] drives = DriveInfo.GetDrives();
                for ( int i = 0; i < drives.Length; i ++ )
                {
                    DriveInfo drive = drives[i];
                    
                    //  Skip the drives we don't want to present to the end user.
                    if ( drive.DriveType == DriveType.Ram ||
                         drive.DriveType == DriveType.NoRootDirectory ||
                         drive.IsReady == false )
                        continue;

                    //  Get the name of the drive, and remove the path separator.
                    //  Also, get the volume name and use 'Local Disk' if none is assigned.
                    string driveName = drive.Name;
                    driveName = driveName.Replace( PATH_SEPARATOR, string.Empty );
                    string volumeLabel = drive.VolumeLabel;
                    volumeLabel = volumeLabel != null && volumeLabel.Length > 0 ? volumeLabel : "Local Disk";

                    //  Create a new UltraNavigationBarLocation instance, using the drive's name
                    //  as the key, and the volume label/drive name as the DisplayText.
                    UltraNavigationBarLocation location = new UltraNavigationBarLocation( driveName, driveName );

                    //  Use the DisplayText property to format the combination of the drive letter
                    //  and volume name so that we present it to the end user in a readable form.
                    location.DisplayText = string.Format("{0} ({1})", volumeLabel, driveName );

                    //  Add the location to the root's Locations collection.
                    locations.Add( location );

                    //  Add an accompanying tree node for the location we just added
                    UltraTreeNode node = rootNode.Nodes.Add( location.Key, location.DisplayTextResolved );

                    //  Assign the appropriate image to the location/node
                    location.Settings.Appearance.Image = this.GetImage(drive.DriveType);
                    node.Override.NodeAppearance.Image = this.GetImage(drive.DriveType);

                    //  Assign an instance of a wrapper class which associates the node,
                    //  location and directory to each object to the Tag property.
                    node.Tag = new DirectoryWrapper( drive.RootDirectory, location );
                    location.Tag = new DirectoryWrapper( drive.RootDirectory, node );
                }
            }
            finally
            {
                System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
            }
        }
    }

Remarks

The RootLocation always appears in the navigation path; when no location has been selected by the end user, the SelectedLocation returns a reference to the root location.

Note: The dropdown button cannot be hidden for the root location, i.e., the UltraNavigationBarLocationSettings.DropDownButtonVisible property is effectively read-only; attempting to hide the dropdown button causes an exception to be thrown.

Note: The UltraNavigationBarRootLocation.IsSelected property always returns true, i.e., the root location is always in the selected state.

See Also