Click here to Skip to main content
6,291,124 members and growing! (15,106 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, Windows, .NET 1.0, Visual Studio, Dev
Posted:20 Sep 2002
Views:78,919
Bookmarked:24 times
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
22 votes for this article.
Popularity: 6.08 Rating: 4.53 out of 5

1

2
1 vote, 7.1%
3
3 votes, 21.4%
4
10 votes, 71.4%
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


Member
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
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  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) Pinmemberslimzhao17:04 23 Aug '07  
GeneralVisual Studio 2005 Bug and Fix PinmemberScott Kuhl7:50 9 Apr '07  
GeneralRe: Visual Studio 2005 Bug and Fix PinmemberPeter Solberg20:07 23 May '07  
GeneralVery useful, thanks! Pinmemberbenno_114:31 19 Nov '06  
GeneralConfigurable Depth PinmemberDrewBurlingame12:35 14 Feb '06  
Generallittle enhancment (you can publish it if you want) PinmemberBnaya Eshet5:53 12 Jan '06  
GeneralGreat. Works with VS 2003 PinmemberMtF_11:40 25 Jul '05  
Generalexcellent, very useful :) Pinmemberfeline_dracoform3:29 22 Jun '05  
GeneralCollapse the subfolders too PinmemberCharles Windhausen13:38 8 Dec '04  
GeneralCan it work for ClassView? PinmemberKevin McFarlane7:29 4 Oct '04  
GeneralRe: Can it work for ClassView? PinmemberErlend21:46 6 Feb '05  
GeneralAbout ToolButton PinsussAnonymous9:18 14 Nov '02  
GeneralRe: About ToolButton PinmemberEdwin Evans19:28 14 Nov '02  
GeneralRe: About ToolButton PinsussAnonymous5:40 15 Nov '02  
GeneralRe: About ToolButton PinmemberBooga5:13 28 Nov '02  
GeneralGreat Macro! PinmemberStephen Jones6:05 4 Oct '02  
GeneralRe: Great Macro! PinmemberEdwin Evans6:25 6 Oct '02  
GeneralRe: Great Macro! PinmemberBooga3:41 23 Jan '03  
GeneralRe: Great Macro! PinmemberEdwin Evans12:00 21 Jun '05  
GeneralRe: Great Macro! PinmemberRandy8710: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-2009
Web16 | Advertise on the Code Project