Logo
BUG: EnvDTE.SelectionEvents.OnChange event does not fire when more than two nodes are already selected in the Solution Explorer of Visual Studio

Author: Carlos J. Quintero (Microsoft MVP) Applies to: Microsoft Visual Studio .NET 2002
Date: April 2007   Microsoft Visual Studio .NET 2003
      Microsoft Visual Studio 2005
Introduction

The OnChange event of the EnvDTE.SelectionEvents class fires each time you select something different in the IDE. For example, if you multi-select a second file in the Solution Explorer, the event is fired. However, it does not fire when you multi-select a third item in the Solution Explorer.

Cause

This seems to be a bug of Visual Studio.

More Information

Steps to reproduce the problem:

  • Open the Macros IDE, go to the EnvironmentEvents file, select the SelectionEvents item in the combobox to the left and the OnChange event in the combobox to the right. This creates the event handler for that event. Add this code:
    Public Sub SelectionEvents_OnChange() Handles SelectionEvents.OnChange
        MessageBox.Show("Change")
    End Sub
  • Go back to the Visual Studio IDE and create a project.
  • Expand the References node in the Solution Explorer.
  • Select a reference in the Solution Explorer and notice that the SelectionEvents.OnChange event is fired (you see the message box).
  • Multi-select (with the Ctrl key) a second reference and notice that the event is fired again. Now you have two items selected.
  • Multi-select a third reference and notice that the event is not fired this time.


Go to the 'Visual Studio Extensibility (VSX)' web site for more articles like this (Articles section)