Click here to Skip to main content
Licence 
First Posted 20 Sep 2002
Views 101,632
Bookmarked 28 times

CollapseAll Macro for Visual Studio .NET

By Edwin Evans | 20 Sep 2002
A simple macro to collapse all the project nodes in the Solution Explorer

1

2
1 vote, 6.7%
3
3 votes, 20.0%
4
11 votes, 73.3%
5
4.82/5 - 23 votes
1 removed
μ 4.54, σa 1.08 [?]

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

Web Developer

United States United States

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.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralGreat Macro! PinmemberDarren Boss6:31 2 Dec '09  
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  
QuestionCan it work for ClassView? PinmemberKevin McFarlane7:29 4 Oct '04  
AnswerRe: 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  
Hi Edwin,
 
Thanks for the reply.
 
I knew how to add a CommandBarControl to a toolbar (via code or using Tools|Customize. However in your screenshot you had added a "CollapseAll" button to a toolbar which seems like part of "Solution Explorer". That toolbar does not seem to be customizable using Tools|Customize.
 
So how did you do it? I will be incorporating this in an add-in.
 
You did mention how can I add a toolbutton to the "Standard" toolbar. But how can I add it to a Solution Explorer toolbar? Is there a string name for that toolbar?
 
I will appreciate your help in this regard.
Thanks.
 
Paresh
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    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.

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