Meeting the needs of your business from a distance

Macro to Collapse All Projects in Solution Explorer in Visual Studio

by Mark Shiffer 10/23/2007 8:49:00 AM

Source from: RaspenJho

Imports System

Imports EnvDTE

Imports System.Diagnostics

Public Module Collapse Sub CollapseAll()

' Get the the Solution Explorer tree

Dim UIHSolutionExplorer As UIHierarchy

UIHSolutionExplorer = DTE.Windows.Item(Constants.vsext_wk_SProjectWindow).Object()

' Check if there is any open solution

If (UIHSolutionExplorer.UIHierarchyItems.Count = 0) Then

' MsgBox("Nothing to collapse. You must have an open solution.")

Return

End If

' Get the top node (the name of the solution)

Dim UIHSolutionRootNode As UIHierarchyItem

UIHSolutionRootNode = UIHSolutionExplorer.UIHierarchyItems.Item(1)

UIHSolutionRootNode.DTE.SuppressUI = True

' Collapse each project node

Dim UIHItem As UIHierarchyItem For Each UIHItem In UIHSolutionRootNode.UIHierarchyItems

'UIHItem.UIHierarchyItems.Expanded = False

If UIHItem.UIHierarchyItems.Expanded Then

Collapse(UIHItem)

End If

Next

' Select the solution node, or else when you click

' on the solution window

' scrollbar, it will synchronize the open document

' with the tree and pop

' out the corresponding node which is probably not what you want.

UIHSolutionRootNode.Select(vsUISelectionType.vsUISelectionTypeSelect)

UIHSolutionRootNode.DTE.SuppressUI = False

End Sub

Private Sub Collapse(ByVal item As UIHierarchyItem) For Each eitem As UIHierarchyItem In item.UIHierarchyItems

If eitem.UIHierarchyItems.Expanded AndAlso eitem.UIHierarchyItems.Count > 0 Then

Collapse(eitem)

End If

Next

item.UIHierarchyItems.Expanded = False

End Sub

End Module

Currently rated 4.0 by 1 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Programs

Related posts

Add comment


(Will show your Gravatar icon)  

  Country flag





Live preview

July 9. 2008 00:25

About the author

Name of author Mark Shiffer
CEO & CIO of MS Consulting

E-mail me Send mail

Calendar

<<  July 2008  >>
MoTuWeThFrSaSu
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

View posts in large calendar

Pages

    Recent posts

    Recent comments

    Disclaimer

    The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

    © Copyright 2008

    Sign in

    Copyright © 2001-2008 MS Consulting, Inc. All Rights Reserved.