Skip to main content
Email Password   helpLost your password?

Sample Image - CollapseAll.gif

Introduction

Visual Studio .NET has a cool feature that it will automatically synchronize the Solution Explorer with the open file. One problem though is that if you have a large number of projects, the number of branches can soon get out of control - you can't see the trees for all the branches, so to speak. This is a very simple macro that you can use to collapse all the project nodes in the Solution Explorer.

Macro Code

    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)

        ' Collapse each project node

        Dim UIHItem As UIHierarchyItem
        For Each UIHItem In UIHSolutionRootNode.UIHierarchyItems
            UIHItem.UIHierarchyItems.Expanded = False
        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)

    End Sub
You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralExcellent work, but DPack plugin for vs.net already do it(although slower than your macro solution) Pin
slimzhao
17:04 23 Aug '07  
GeneralVisual Studio 2005 Bug and Fix Pin
Scott Kuhl
7:50 9 Apr '07  
GeneralRe: Visual Studio 2005 Bug and Fix Pin
Peter Solberg
20:07 23 May '07  
GeneralVery useful, thanks! Pin
benno_1
14:31 19 Nov '06  
GeneralConfigurable Depth Pin
DrewBurlingame
12:35 14 Feb '06  
Generallittle enhancment (you can publish it if you want) Pin
Bnaya Eshet
5:53 12 Jan '06  
GeneralGreat. Works with VS 2003 Pin
MtF_
11:40 25 Jul '05  
Generalexcellent, very useful :) Pin
feline_dracoform
3:29 22 Jun '05  
GeneralCollapse the subfolders too Pin
Charles Windhausen
13:38 8 Dec '04  
GeneralCan it work for ClassView? Pin
Kevin McFarlane
7:29 4 Oct '04  
GeneralRe: Can it work for ClassView? Pin
Erlend
21:46 6 Feb '05  
GeneralAbout ToolButton Pin
Anonymous
9:18 14 Nov '02  
GeneralRe: About ToolButton Pin
Edwin Evans
19:28 14 Nov '02  
GeneralRe: About ToolButton Pin
Anonymous
5:40 15 Nov '02  
GeneralRe: About ToolButton Pin
Booga
5:13 28 Nov '02  
GeneralGreat Macro! Pin
Stephen Jones
6:05 4 Oct '02  
GeneralRe: Great Macro! Pin
Edwin Evans
6:25 6 Oct '02  
GeneralRe: Great Macro! Pin
Booga
3:41 23 Jan '03  
GeneralRe: Great Macro! Pin
Edwin Evans
12:00 21 Jun '05  
GeneralRe: Great Macro! Pin
Randy87
10:43 23 Jul '07  


Last Updated 20 Sep 2002 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2009