Click here to Skip to main content
11,413,961 members (73,679 online)
Click here to Skip to main content

CollapseAll Macro for Visual Studio .NET

, 20 Sep 2002
Rate this:
Please Sign up or sign in to vote.
A simple macro to collapse all the project nodes in the Solution Explorer

Sample Image - CollapseAll.gif

<!-- Add the rest of your HTML here -->

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.

<!-- Add the rest of your HTML here -->

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

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Edwin Evans
Web Developer
United States United States
Edwin Evans lives with his wife and daughter in Santa Clara, California. He is the creator of HandyFind, a faster, friendlier way to find words in documents and Web pages. Edwin is also working to help create the technological Singularity by supporting the Singularity Institute for Artificial Intelligence.

Comments and Discussions

 
GeneralGreat Macro! Pin
Darren Boss, 2-Dec-09 6:31
memberDarren Boss2-Dec-09 6:31 
GeneralExcellent work, but DPack plugin for vs.net already do it(although slower than your macro solution) Pin
slimzhao, 23-Aug-07 17:04
memberslimzhao23-Aug-07 17:04 
GeneralVisual Studio 2005 Bug and Fix Pin
Scott Kuhl, 9-Apr-07 7:50
memberScott Kuhl9-Apr-07 7:50 
GeneralRe: Visual Studio 2005 Bug and Fix Pin
Peter Solberg, 23-May-07 20:07
memberPeter Solberg23-May-07 20:07 
GeneralVery useful, thanks! Pin
benno_1, 19-Nov-06 14:31
memberbenno_119-Nov-06 14:31 
GeneralConfigurable Depth Pin
DrewBurlingame, 14-Feb-06 12:35
memberDrewBurlingame14-Feb-06 12:35 
Generallittle enhancment (you can publish it if you want) Pin
Bnaya Eshet, 12-Jan-06 5:53
memberBnaya Eshet12-Jan-06 5:53 
GeneralGreat. Works with VS 2003 Pin
MtF_, 25-Jul-05 11:40
memberMtF_25-Jul-05 11:40 
Generalexcellent, very useful :) Pin
feline_dracoform, 22-Jun-05 3:29
memberfeline_dracoform22-Jun-05 3:29 
while i am not a total fan of having the solution explorer follow the open code, i find i need to keep it turned on since it causes more problems turning it off.

as a result a rather large tree ends up open all over the place, making a complete mess. this is ideal Big Grin | :-D Rose | [Rose]

zen is the art of being at one with the two'ness
GeneralCollapse the subfolders too Pin
Charles Windhausen, 8-Dec-04 13:38
memberCharles Windhausen8-Dec-04 13:38 
QuestionCan it work for ClassView? Pin
Kevin McFarlane, 4-Oct-04 7:29
memberKevin McFarlane4-Oct-04 7:29 
AnswerRe: Can it work for ClassView? Pin
Erlend, 6-Feb-05 21:46
memberErlend6-Feb-05 21:46 
GeneralAbout ToolButton Pin
Anonymous, 14-Nov-02 9:18
sussAnonymous14-Nov-02 9:18 
GeneralRe: About ToolButton Pin
Edwin Evans, 14-Nov-02 19:28
memberEdwin Evans14-Nov-02 19:28 
GeneralRe: About ToolButton Pin
Anonymous, 15-Nov-02 5:40
sussAnonymous15-Nov-02 5:40 
GeneralRe: About ToolButton Pin
Booga, 28-Nov-02 5:13
memberBooga28-Nov-02 5:13 
GeneralGreat Macro! Pin
Stephen Jones, 4-Oct-02 6:05
memberStephen Jones4-Oct-02 6:05 
GeneralRe: Great Macro! Pin
Edwin Evans, 6-Oct-02 6:25
memberEdwin Evans6-Oct-02 6:25 
GeneralRe: Great Macro! Pin
Booga, 23-Jan-03 3:41
memberBooga23-Jan-03 3:41 
GeneralRe: Great Macro! Pin
Edwin Evans, 21-Jun-05 12:00
memberEdwin Evans21-Jun-05 12:00 
GeneralRe: Great Macro! Pin
Randy87, 23-Jul-07 10:43
memberRandy8723-Jul-07 10:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150427.2 | Last Updated 21 Sep 2002
Article Copyright 2002 by Edwin Evans
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid