Export (0) Print
Expand All

UIHierarchy Object

Visual Studio .NET 2003

Represents standard tool windows in the integrated development environment (IDE) that use hierarchical trees of data, such as Solution Explorer, the Server Explorer, and the Macro Explorer.

DTE

   Windows

      Window

         UIHierarchy

[Visual Basic .NET]
Public Interface UIHierarchy
    Inherits IDispatch
[Visual Basic 6]
Class UIHierarchy
[C++]
interface UIHierarchy : IDispatch
[C#]
public interface UIHierarchy : IDispatch
[JScript .NET]
public interface UIHierarchy extends IDispatch

Remarks

The UIHierarchy object provides a common object model for standard tool windows that present hierarchical data in a tree view. You can select items regardless of whether the expansion state of the tree shows the item. Selecting an item that is not shown in the current tree expansion causes the tree to expand to show the item.

You obtain this object using Window.Object on any standard tree view tool window.

Since the UIHierarchy object represents any tree view-type window, such as Solution Explorer or Macro Explorer, it is a Window object. Its UIHierarchyItems property returns the collection of top-level nodes in the specified window. In Solution Explorer, there is only a single top-level node (the solution), and in Macro Explorer, there is also only one top-level node (the Macros node). This means that the project nodes are not in the window's UIHierarchyItems collection, but rather in the top-level node's collection.

Bearing this in mind, there are two ways to access a particular node (UIHierarchyItem):

  • Using the GetItem method to directly reference the desired node.
  • Using UIHierarchyItems.Item.UIHierarchyItems... (a collection/item/collection... pattern). To navigate deeper into a node nesting, just keep using this pattern. For example, to navigate to the second node under the top-level node, you would use UIHierarchy.UIHierarchyItems.Item(1).UIHierarchyItems.Item(2).

Examples of how to use both techniques to access a lower-level node are demonstrated below.

Requirements

Namespace: EnvDTE

File: dte.olb

Example

This example uses the GetItem method strategy of accessing a node in an UIHierarchy.

Sub UIHierarchyExample1()
   'Reference the UIHierarchy, UIHierarchyItem, and OutputWindow objects.
   Dim UIH As UIHierarchy = _
     DTE.Windows.Item(Constants.vsWindowKindMacroExplorer).Object
   Dim samples As UIHierarchyItem = UIH.GetItem("Macros\Samples")
   Dim OWPane As OutputWindowPane = GetOutputWindowPane("List Macros")
   Dim file As UIHierarchyItem

   OWPane.Clear()
   For Each file In samples.UIHierarchyItems
      OWPane.OutputString(file.Name & _
        Microsoft.VisualBasic.Constants.vbCrLf)
      Dim macro As UIHierarchyItem
      For Each macro In file.UIHierarchyItems
         OWPane.OutputString("   " & macro.Name & _
           Microsoft.VisualBasic.Constants.vbCrLf)
      Next
   Next
End Sub

Function GetOutputWindowPane(ByVal Name As String, Optional ByVal show _
  As Boolean = True) As OutputWindowPane
   Dim win As Window = _
     DTE.Windows.Item(EnvDTE.Constants.vsWindowKindOutput)
   If show Then win.Visible = True
   Dim ow As OutputWindow = win.Object
   Dim owpane As OutputWindowPane
   Try
      owpane = ow.OutputWindowPanes.Item(Name)
   Catch e As System.Exception
      owpane = ow.OutputWindowPanes.Add(Name)
   End Try
   owpane.Activate()
   Return owpane
End Function

This example uses the UIHierarchyItems.Item.UIHierarchyItems strategy for accessing a node in a UIHierarchy.

Sub UIHierarchyExample2()
   Dim UIH As UIHierarchy = _
     DTE.Windows.Item(Constants.vsWindowKindMacroExplorer).Object
     ' Set a reference to the "Samples" node in Macro Explorer. The 
     ' collections are one-based.
     Dim UIHItem As UIHierarchyItem = _
     UIH.UIHierarchyItems.Item(1).UIHierarchyItems.Item(2)
   Dim file As UIHierarchyItem
   Dim OWPane As OutputWindowPane = GetOutputWindowPane("List Macros")
   For Each file In UIHItem.UIHierarchyItems
      OWPane.OutputString(file.Name & _
        Microsoft.VisualBasic.Constants.vbCrLf)
      Dim macro As UIHierarchyItem
      For Each macro In file.UIHierarchyItems
         OWPane.OutputString("   " & macro.Name & _
           Microsoft.VisualBasic.Constants.vbCrLf)
      Next
   Next
End Sub

See Also

Manipulating Tree Views Using UIHierarchy | UIHierarchyItem Object | UIHierarchyItems Collection | UIHierarchyItems Property (General Extensibility) | Properties, Methods, and Events

Show:
© 2015 Microsoft