5,696,038 members and growing! (14,063 online)
Email Password   helpLost your password?
General Programming » Macros and Add-ins » Macros     Intermediate

CollapseAll Macro for Visual Studio .NET

By Edwin Evans

A simple macro to collapse all the project nodes in the Solution Explorer
VB, VC7, C++, Windows, .NET, .NET 1.0, Visual Studio, Dev

Posted: 20 Sep 2002
Updated: 20 Sep 2002
Views: 71,560
Bookmarked: 21 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
21 votes for this Article.
Popularity: 5.97 Rating: 4.52 out of 5
0 votes, 0.0%
1
0 votes, 0.0%
2
1 vote, 7.7%
3
3 votes, 23.1%
4
9 votes, 69.2%
5

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

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

About the Author

Edwin Evans


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.
Occupation: Web Developer
Location: United States United States

Other popular Macros and Add-ins articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 20 of 20 (Total in Forum: 20) (Refresh)FirstPrevNext
GeneralExcellent work, but DPack plugin for vs.net already do it(although slower than your macro solution)memberslimzhao17:04 23 Aug '07  
GeneralVisual Studio 2005 Bug and FixmemberScott Kuhl7:50 9 Apr '07  
GeneralRe: Visual Studio 2005 Bug and FixmemberPeter Solberg20:07 23 May '07  
GeneralVery useful, thanks!memberbenno_114:31 19 Nov '06  
GeneralConfigurable DepthmemberDrewBurlingame12:35 14 Feb '06  
Generallittle enhancment (you can publish it if you want)memberBnaya Eshet5:53 12 Jan '06  
GeneralGreat. Works with VS 2003memberMtF_11:40 25 Jul '05  
Generalexcellent, very useful :)memberfeline_dracoform3:29 22 Jun '05  
GeneralCollapse the subfolders toomemberCharles Windhausen13:38 8 Dec '04  
GeneralCan it work for ClassView?memberKevin McFarlane7:29 4 Oct '04  
GeneralRe: Can it work for ClassView?memberErlend21:46 6 Feb '05  
GeneralAbout ToolButtonsussAnonymous9:18 14 Nov '02  
GeneralRe: About ToolButtonmemberEdwin Evans19:28 14 Nov '02  
GeneralRe: About ToolButtonsussAnonymous5:40 15 Nov '02  
GeneralRe: About ToolButtonmemberBooga5:13 28 Nov '02  
GeneralGreat Macro!memberStephen Jones6:05 4 Oct '02  
GeneralRe: Great Macro!memberEdwin Evans6:25 6 Oct '02  
GeneralRe: Great Macro!memberBooga3:41 23 Jan '03  
GeneralRe: Great Macro!memberEdwin Evans12:00 21 Jun '05  
GeneralRe: Great Macro!memberRandy8710:43 23 Jul '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 20 Sep 2002
Editor: Nishant Sivakumar
Copyright 2002 by Edwin Evans
Everything else Copyright © CodeProject, 1999-2008
Web08 | Advertise on the Code Project