APEXA, LLC
Blog Gallery Contact

How do I collapse all Projects in Visual Studio?

Blog Date: Wednesday, April 28, 2010 - Discuss below!

 Recent Blogs << Back

ASP.NET MVC Login complete Forms Authentication 3/19/2010

jQuery AJAX in ASP.NET MVC $.getJSON, $get, $.post 3/24/2010

Defensive Programming in Microsoft C# .NET 4/2/2010

 More...
 

IT Jobs Hiring


Cisco Voice Operations Engineer New York, NY

Sr. Software Engineer -- DSP Algorithms, Security Encryption, C/C++ (San Diego, CA ) Los Angeles Area, CA

Software Engineer (West L.A.) Los Angeles Area, CA

More jobs...
 

This is a common question I get asked a lot. It is something that should have been included, because in the real-world, there could be over a dozen projects. The solution is a simple Macro added to Visual Studio. The following is the code from this website.

Imports System
Imports EnvDTE
Imports System.Diagnostics

Public Module Collapse
    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)
        UIHSolutionRootNode.DTE.SuppressUI = True
        ' Collapse each project node
        Dim UIHItem As UIHierarchyItem
        For Each UIHItem In UIHSolutionRootNode.UIHierarchyItems
            'UIHItem.UIHierarchyItems.Expanded = False
            If UIHItem.UIHierarchyItems.Expanded Then
                Collapse(UIHItem)
            End If
        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)
        UIHSolutionRootNode.DTE.SuppressUI = False
    End Sub

    Private Sub Collapse(ByVal item As UIHierarchyItem)
        For Each eitem As UIHierarchyItem In item.UIHierarchyItems
            If eitem.UIHierarchyItems.Expanded AndAlso eitem.UIHierarchyItems.Count > 0 Then
                Collapse(eitem)
            End If
        Next
        item.UIHierarchyItems.Expanded = False
    End Sub
End Module

I recommend going to the website to see all the screenshots: http://it.toolbox.com/blogs/think-clients/visual-studio-macro-collapse-solution-explorer-18035



Wednesday, April 28, 2010 12:49:42 PM

Home | Gallery | Contact | IT Consulting | Web Marketing | Search Engine Optimization | Web Design & CMS | My Blog on C# .NET

Site Map | Copyright 2007 Web Design web design | Developed by APEXA, LLC

APEXA, LLC