170

I know that I can use Arrow Keys to collapse items of solution explorer one by one, but I would like to know if there is a way to collapse all items with only one operation. I want to know it because, today I have a solution with 6 projects that have at least two hundred files and if I try to collapse them one-by-one I will have a hard time.

Tree View - Solution Explorer (Visual Studio)

Vivek Nuna
  • 25,472
  • 25
  • 109
  • 197
Cleiton
  • 17,663
  • 13
  • 46
  • 59

14 Answers14

226

It appears to be built in by default in Visual Studio 2013 onwards.

Solution Explorer > Collapse

Sebastian Patten
  • 7,157
  • 4
  • 45
  • 51
24

If you have ReSharper installed, you can right click on the solution in the solution explorer, and select "Collapse All".

Pete
  • 12,206
  • 8
  • 54
  • 70
21

You can use PowerCommands for Visual Studio 2008

Right click on the project\solution on the solution explorer and choose Collapse Project:

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
HuBeZa
  • 4,715
  • 3
  • 36
  • 58
15

Just use the number pad's Plus + and Minus - keys at the top-level node, to expand and collapse respectively (Note: * also expands the whole list.)

For the toolbox, you need to use * and / instead for expand/collapse. Go figure.

Mwiza
  • 7,780
  • 3
  • 46
  • 42
AL.
  • 159
  • 1
  • 2
  • 3
    Unfortunately this only collapses/expands the current node (just like clicking on the expand/collapse icon), not any children, which I don't think is a solution for the OP: for instance if you have 3 projects, each with 2 folders, each with 10 folders. Collapsing the solution as a whole is great, but when you expand it again you're back to a list of 60 items rather than a list of 3 projects. – DaveD Jun 15 '12 at 14:14
  • 2
    Num pad * expands all childrens (VS 2013) – Sel Jun 10 '15 at 06:49
14

In VS 2019 just click Collapse All

enter image description here

Alan Simpson
  • 447
  • 5
  • 5
10

If you have Resharper installed, there is an option called Collapse All and a shortcut key next to it.

Solution Explorer > Resharper > Collapse

Now this shortcut key will not work for you ! Unless you set it up using Tools > Options > Keyboard.

The command name is ReSharper_CollapseInSolutionExplorer.

Search using this command name and assign a shortcut key of your choice.

Options > Keyboard > ReSharper_CollapseInSolutionExplorer

and you now have a shortcut key ready to use to collapse all items in your solution explorer.

I know I am a little late to this discussion, but this surely gonna help some one or other.

Madis Otenurm
  • 61
  • 1
  • 7
Yasser Shaikh
  • 46,934
  • 46
  • 204
  • 281
  • 6
    It should be mentioned that this is not default VS functionality (pre 2012), but, in this instance, the additional context menu item and shortcut is provided by Resharper. – kodjeff1 Jul 30 '13 at 18:36
  • In VS2015 with ReSharper 2016.1 this is now just `CollapseInSolutionExplorer`. – absynce Jun 02 '16 at 16:19
6

Using Visual Studio 2017 and above

use shortcut

  • Open Tools > Options or press Alt + T + O
  • Under Environment tab > Keyboard (Also, you can create a shortcut for Tools.CustomizeKeyboard to open it directly)

To Collapse All

  • Search for "SolutionExplorer.CollapseAll"
  • Add a new shortcut for example Ctrl+Left Arrow,Ctrl+Left Arrow

To Expand All

  • Search for "SolutionExplorer.Folder.CollapseAll"
  • Add a new shortcut for example Ctrl+Right Arrow,Ctrl+Right Arrow

    enter image description here

  • Assign > OK

Anas Alweish
  • 2,818
  • 4
  • 30
  • 44
4

The VisualStudio extension CodeMaid provides collapsing.

Download from VisualStudioGallery.

The current version only supports VS2010 or higher, but you can install older versions side-by-side.

Em1
  • 1,077
  • 18
  • 38
4

There's a macro at Link for Visual Studio 2005.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
TLiebe
  • 7,913
  • 1
  • 23
  • 28
2

Visual Studio 2012 is out on 8/15/2012, so I suggest upgrading to that to get a fast "Collapse All" toolbar button previously available only in the Productivity Power Tools' Solution Navigator, which was sometimes too slow to be usable.

Patrick Szalapski
  • 8,738
  • 11
  • 67
  • 129
0

It’s very simple now in visual studio 2022 17.7 version. It’s easier and more flexible.

When you right-click on a node in Solution Explorer. You can use this to collapse the selected node as well as its descendent nodes. We've also mapped this as a shortcut via the Ctrl+Left arrow keys.

from one YouTube channel

Reference: https://learn.microsoft.com/en-us/visualstudio/releases/2022/release-notes#collapse-all-descendants-for-solution-explorer

Vivek Nuna
  • 25,472
  • 25
  • 109
  • 197
-1

Use the Visual Studio extension that fits your version of Visual Studio. In my case (I use Visual Studio 2012) I use the extension Productivity Power Tools, but, unfortunately this exist only for VS 2010 and latter... For VS 2008 there is a similar extension: Power Commands.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
serge
  • 13,940
  • 35
  • 121
  • 205
-4

Delete the *.suo and *.csproj.user files, and reopen the solution/projects.

Cecil Has a Name
  • 4,962
  • 1
  • 29
  • 31