‘Collapse All’ in Visual Studio

We have tons of sub-folders in our main client project, and every time you access a file in a sub-folder Visual Studio expands the sub-folder, and given how many files we have in these sub-folders, the scroll bar quickly becomes a tiny dot.

Once their open, there’s no easy way to collapse them all except to go through by hand and manually collapse each one again.

The Visual Studio team gave me the following reply to my suggestion for a “Collapse All” ¬†feature:

Posted by Microsoft on 3/29/2010 at 2:10 PM
Thanks for your feedback. This is a good suggestion and one that we unfortunately cannot incorporate in VS2010. However, here is a macro that should help in the meanwhile:

    Sub UIHierarchy_CollapseTree()
        Dim Hierarchy As UIHierarchy

        'Change Hierarchy to the following line to collapse the active window
        'Hierarchy = DTE.ActiveWindow.Object
        Hierarchy = DTE.Windows.Item(Constants.vsWindowKindSolutionExplorer).Object

        CollapseHierarchyItems(Hierarchy.UIHierarchyItems)
    End Sub
    Sub CollapseHierarchyItems(ByVal HierarchyItems As UIHierarchyItems)
        Dim SubHierarchyItem As UIHierarchyItem
        For Each SubHierarchyItem In HierarchyItems
            CollapseHierarchyItems(SubHierarchyItem.UIHierarchyItems)
            SubHierarchyItem.UIHierarchyItems.Expanded = False
        Next
    End Sub

2 Comments

Leave a Reply

Name and email address are required. Your email address will not be published.

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

You may use these HTML tags and attributes:

<a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <pre> <q cite=""> <s> <strike> <strong> 

%d bloggers like this: