IVsTrackSelectionEx not working the first time on a ToolWindowPane RRS feed

  • Question

  • I created a toolwindow pane, when i call the IVsTrackSelection, it changes the property grid fine.

    But it does not work if my tool window pane was active at start up. It start working correctly if i change the active window and come back. 

    Please help

    Monday, August 13, 2012 1:56 PM

All replies

  • Hi Henri76,

    Where do you define your IVsTrackSelectionEx, on Initialize or on other events?

    Can you show some sample codes here?

    Best regards,

    Ego [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, August 14, 2012 6:57 AM
  • Hi,

    I get the IVsTrackSelectionEx from the tool window service. I get it every time the selection changes.

    I was able to fix the problem by hiding and showing the related IVsWindowFrame the first time a make a selection.

    I am on Visual Studio isolated shell 2010.

    Wednesday, August 15, 2012 2:41 PM
  • Where exactly are you calling it? In your toolwindow ctor?  In its Initialize method?  Somewhere else?


    Thursday, August 16, 2012 5:43 PM
  • Everything is initialized. The method is trigger from a mouse click.


    Tuesday, September 18, 2012 2:26 PM
  • So you are saying it only works if you click on your window? What were you expecting? Code that runs on mouse click only runs on mouse click. VS doesn't send your window a mouse click unless you click on it.


    Tuesday, September 18, 2012 2:43 PM
  • I will forget the last reply and try to explain it again.

      • The ToolWindowPane is loaded, it is visible, it is the first active window in visual studio 2010 isolated shell. The property window is open but inactive.
      • I click on my active ToolWindowPane and it triggers an event.
      • In this method, i call IVsTrackSelectionEx to update the property window but nothing happens.

    If i click on another window and come back, everything is works fine. This only occurs the first time i call IVsTrackSelectionEx.

    Interesting fact, if i hide and activate this window programmatically on my first try,  It is working but causes other bugs in the application and is unacceptable.


    Thursday, September 20, 2012 1:05 PM
  • I would need a repro, the reason clicking on it likely does nothing is that it determines nothing has actually changed. Whether this is a break-down in communication between the monitor selection service or with the property window itself is not clear. Generally repros or complete code are necessary to diagnose things like this, otherwise we are just trying to guess, which tends to not be effective.


    Thursday, September 20, 2012 5:31 PM
  • I can confirm that this also occurs in Visual Studio 2012.

    I have a simple tool window with a tree view, which changes the tracked selection on select of an item. When the tool window is the first window that gets the focus when starting VS, the property window doesn't respond to IVsTrackSelection.OnSelectChange. When I switch to another window, and back again, the property window works perfectly.

    Did you find a solution for this problem?



    Tuesday, October 30, 2012 10:45 PM
  • I didn't, as I said repros are needed for these kind of things, otherwise I am just guessing, which tends to be a non-productive debugging technique.


    Tuesday, October 30, 2012 11:05 PM
  • You can reproduce it following these steps in Visual Studio 2012:

    - Create a new Visual Studio Package project.

    - In the wizard, click Next, choose Visual C# as language and click Next, and Next again.

    - Click the checkbox 'Tool Window', and click Next, Next again and Finish.

    - Open MyToolWindow.cs in the package project.

    - Replace the constructor with the following code:

    public MyToolWindow() : base(null)
     this.Caption = Resources.ToolWindowTitle;
     this.BitmapResourceID = 301;
     this.BitmapIndex = 1;

     var button = new System.Windows.Controls.Button { Content = "Click me" };

     button.Click += (o, e) =>
      var track = this.GetService(typeof(STrackSelection)) as ITrackSelection;

      if (track != null)
       track.OnSelectChange(new SelectionContainer() { SelectedObjects = new[] { button } });  

     base.Content = button;

    - Run the project. Open the properties window using F4, and the tool window via the menu View -> Other Windows -> My Tool Window.

    - Close the experimental instance of Visual Studio.

    - Run the project again. Both the Tool window and properties window are now open.

    - Click the button. Nothing happens.

    - Click on any other window (the start screen for example), and click the button again. The properties window now shows the expected result.

    The problem is that the first time you click, the properties window stays empty. Are there any initialization steps I am missing?

    Wednesday, October 31, 2012 9:31 AM
  • The solution is to invoke an OnSelectChange with a SelectionContainer having both SelectableObjects and SelectedObject set to null before doing anything else.

    You would typically do this in the OnToolWindowCreated like so;

    public override void OnToolWindowCreated()
    var track = (ITrackSelection)GetService(typeof(STrackSelection));
      track.OnSelectChange(new SelectionContainer{ SelectableObjects = null, SelectedObject = null});


    • Edited by Koen Zwikstra Tuesday, August 6, 2013 9:04 PM
    • Proposed as answer by weekeew Thursday, December 1, 2016 5:39 AM
    Tuesday, August 6, 2013 9:02 PM
  • it solves the problem.
    Thursday, December 1, 2016 5:40 AM