44

In Visual Studio 2005, whenever I would view a file in the main editor, the Solution Explorer would find and highlight that file. Some time ago, this stopped working and the Solution Explorer would do nothing.

This has become quite a pain since following a chain of "Go To Definition"s can lead you all over your solution. Where is the setting to turn this back on?

1
  • This started happening to me, and didn't knew how to fix it. Thanks for the question. Commented Jun 18, 2009 at 14:10

6 Answers 6

65

Click on the Tools → Options menu. Select the Projects and Solutions → General option page.

Make sure "Track active item in Solution Explorer" is checked. That should do it.

1
35

I like to keep this option turned off (especially when working with a big project), but it's useful to be able to find the file in the tree now and then. I found a way to do this here.

I hope I'm not being too verbose here, but here's the guide to making this work that I wrote for my work's wiki:

  1. Go to Tools->Macros->Macro Explorer.
  2. In the Macro Explorer tree that comes up, right-click MyMacros, and then New Module....
  3. Call the new module SyncItem (if you want).
  4. Right-click the new module, then Edit.
  5. Paste this into the code window. (I don't know or care if the Imports lines are necessary; they're just there by default.)

code:

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics

Public Module SyncItem

    Sub SyncSolutionExplorer()
        DTE.ExecuteCommand("View.TrackActivityinSolutionExplorer")
        DTE.ExecuteCommand("View.TrackActivityinSolutionExplorer")
    End Sub

End Module

The macro is most useful if you bind it to a keystroke. Here's how to do that:

  1. Go to Tools->Options, then select Environment->Keyboard.
  2. Find the new macro in the list (start typing "syncitem" or similar in the search box).
  3. I choose Alt-Shift-T (which this dialog box likes to call Shift-Alt-T) for, um, "Tree," I guess? If you're a fan of Edit.LineTranspose, whatever that is (I think it swaps the current line with the following one), then you might like to pick a different shortcut.
7
  • 1
    The great thing about this approach is it works even if the project containing the active item is within a closed solution folder. That's why the command has to be executed twice. You don't get that with built-in 'track active item', which only works if the containing project is already open.
    – piers7
    Commented Jul 13, 2009 at 7:04
  • 2
    Nice, I suspect Track Active Item of regularly killing VS with my 53-project solution.
    – Benjol
    Commented Aug 20, 2009 at 13:04
  • 1
    I created a walk-through with pics. bitnative.com/2012/05/01/…
    – Cory House
    Commented May 2, 2012 at 5:30
  • Deserves + 10 if I could. Cory, fantastic walk-through. Commented Aug 24, 2012 at 15:30
  • 1
    I bound it to Ctrl [ + s, so it's the same in VS2012 an VS2010 on my machine now! Really great tutorial!
    – Jaap
    Commented Nov 21, 2012 at 14:40
16

I just discovered that ReSharper can do what Owen suggests. I have disabled the "Track active item in Solution Explorer"-setting, and when I'm working in a source-file I press Shift + Alt + L and the file is selected in the Solution Explorer. I haven't changed the binding, so I guess that is the default. The upside to this is that you don't have to create a macro and then bind it to a keystroke (although not very difficult, it still has to be done). The downside is that ReSharper isn't free, so it's probably not a solution for everybody.

4
  • Alt+Shift+L is not a default binding in VS2010 + ReSharper 5 but can be easily added. Thanks. Commented Feb 25, 2010 at 9:51
  • Alt+Shift+L was bound for me by default, but I use R# shortcuts not VS when installing R#.
    – ScottS
    Commented Sep 21, 2010 at 18:28
  • Can someone with R# verify this works? I'm suspecting that what the OP and @ScottS did was disable "track active item" and then the next usage of Shift+Alt+L re-enabled active tracking which will then highlight the current file in the solution explorer. If you have R# and this works, can you check your keyboard bindings and post back with the command name associated with your keyboard shortcut? Commented Aug 12, 2011 at 0:38
  • Looks like this does work with R#; you need to map your keyboard shortcut to: ReSharper.ReSharper_LocateInSolutionExplorerAction Commented Aug 12, 2011 at 0:53
13
  1. Navigate to Tools -> Options
  2. Select "Projects and Solutions" in the tree view on the left
  3. Select "Track Active Item in Solution Explorer"
3

Tools->Options->Project and Solutions->General

Check the box "Track Active Item in Solution Explorer"

2

Tools -> Options -> Environment -> Keyboard

Assign the command

View.TrackActivityinSolutionExplorer

(I use Alt+L)

then to use always hit Alt+L followed by Alt+L

which turns on the feature and locates the file in the source tree and then turns it off again to stop the location bouncing around when you do not want it to.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.