Click here to Skip to main content
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! PinmemberDarren Boss2-Dec-09 6:31 
GeneralExcellent work, but DPack plugin for vs.net already do it(although slower than your macro solution) Pinmemberslimzhao23-Aug-07 17:04 
GeneralVisual Studio 2005 Bug and Fix PinmemberScott Kuhl9-Apr-07 7:50 
GeneralRe: Visual Studio 2005 Bug and Fix PinmemberPeter Solberg23-May-07 20:07 
GeneralVery useful, thanks! Pinmemberbenno_119-Nov-06 14:31 
GeneralConfigurable Depth PinmemberDrewBurlingame14-Feb-06 12:35 
Generallittle enhancment (you can publish it if you want) PinmemberBnaya Eshet12-Jan-06 5:53 
GeneralGreat. Works with VS 2003 PinmemberMtF_25-Jul-05 11:40 
Generalexcellent, very useful :) Pinmemberfeline_dracoform22-Jun-05 3:29 
GeneralCollapse the subfolders too PinmemberCharles Windhausen8-Dec-04 13:38 
QuestionCan it work for ClassView? PinmemberKevin McFarlane4-Oct-04 7:29 
AnswerRe: Can it work for ClassView? PinmemberErlend6-Feb-05 21:46 
GeneralAbout ToolButton PinsussAnonymous14-Nov-02 9:18 
GeneralRe: About ToolButton PinmemberEdwin Evans14-Nov-02 19:28 
GeneralRe: About ToolButton PinsussAnonymous15-Nov-02 5:40 
GeneralRe: About ToolButton PinmemberBooga28-Nov-02 5:13 
GeneralGreat Macro! PinmemberStephen Jones4-Oct-02 6:05 
GeneralRe: Great Macro! PinmemberEdwin Evans6-Oct-02 6:25 
GeneralRe: Great Macro! PinmemberBooga23-Jan-03 3:41 
GeneralRe: Great Macro! PinmemberEdwin Evans21-Jun-05 12:00 
GeneralRe: Great Macro! PinmemberRandy8723-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
Web02 | 2.8.1411023.1 | Last Updated 21 Sep 2002
Article Copyright 2002 by Edwin Evans
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid