Click here to Skip to main content
11,492,385 members (63,138 online)
Click here to Skip to main content

CollapseAll Macro for Visual Studio .NET

, 20 Sep 2002 116.1K 27
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 Boss2-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
slimzhao23-Aug-07 17:04
memberslimzhao23-Aug-07 17:04 
GeneralVisual Studio 2005 Bug and Fix Pin
Scott Kuhl9-Apr-07 7:50
memberScott Kuhl9-Apr-07 7:50 
GeneralRe: Visual Studio 2005 Bug and Fix Pin
Peter Solberg23-May-07 20:07
memberPeter Solberg23-May-07 20:07 
GeneralVery useful, thanks! Pin
benno_119-Nov-06 14:31
memberbenno_119-Nov-06 14:31 
GeneralConfigurable Depth Pin
DrewBurlingame14-Feb-06 12:35
memberDrewBurlingame14-Feb-06 12:35 
Generallittle enhancment (you can publish it if you want) Pin
Bnaya Eshet12-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_dracoform22-Jun-05 3:29
memberfeline_dracoform22-Jun-05 3:29 
GeneralCollapse the subfolders too Pin
Charles Windhausen8-Dec-04 13:38
memberCharles Windhausen8-Dec-04 13:38 
QuestionCan it work for ClassView? Pin
Kevin McFarlane4-Oct-04 7:29
memberKevin McFarlane4-Oct-04 7:29 
AnswerRe: Can it work for ClassView? Pin
Erlend6-Feb-05 21:46
memberErlend6-Feb-05 21:46 
GeneralAbout ToolButton Pin
Anonymous14-Nov-02 9:18
sussAnonymous14-Nov-02 9:18 
GeneralRe: About ToolButton Pin
Edwin Evans14-Nov-02 19:28
memberEdwin Evans14-Nov-02 19:28 
GeneralRe: About ToolButton Pin
Anonymous15-Nov-02 5:40
sussAnonymous15-Nov-02 5:40 
GeneralRe: About ToolButton Pin
Booga28-Nov-02 5:13
memberBooga28-Nov-02 5:13 
GeneralGreat Macro! Pin
Stephen Jones4-Oct-02 6:05
memberStephen Jones4-Oct-02 6:05 
This is a great macro, but I wouldn't call the auto-sync feature in the Solution Explorer a "great feature" Eek! | :eek: .
Thanks,
- Stephen Jones
GeneralRe: Great Macro! Pin
Edwin Evans6-Oct-02 6:25
memberEdwin Evans6-Oct-02 6:25 
GeneralRe: Great Macro! Pin
Booga23-Jan-03 3:41
memberBooga23-Jan-03 3:41 
GeneralRe: Great Macro! Pin
Edwin Evans21-Jun-05 12:00
memberEdwin Evans21-Jun-05 12:00 
GeneralRe: Great Macro! Pin
Randy8723-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
Web04 | 2.8.150520.1 | Last Updated 21 Sep 2002
Article Copyright 2002 by Edwin Evans
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid