views:

18

answers:

0

I want to configure the Visual Studio toolbox each time the user switches between documents in the editor. For that purpose I implemented an add-in with the following method, which is called upon activation of a document window:

private void ConfigureToolbox()
{
    EnvDTE.ToolBoxTab myTab = GetTab("My Tab");

    // fix for VS bug (see http://weblogs.asp.net/savanness/archive/2003/03/18/4019.aspx)
    myTab.Activate();
    myTab.ToolBoxItems.Item(1).Select();

    ToolBoxItem newItem = myTab.ToolBoxItems.Add("CSC.AspNet.CS.Controls.WelcomeLabel", "<PATH TO MY SERVER CONTROLS ASSEMBLY>", vsToolBoxItemFormat.vsToolBoxItemFormatDotNETComponent);
}

private EnvDTE.ToolBoxTab GetTab(String tabName)
{ 
    //Check to see if the Tab already exists..
    foreach (EnvDTE.ToolBoxTab tab in _toolbox.ToolBoxTabs)
    {
        if (tab.Name.Equals(tabName))
        return tab;
    }

    //If not then add the Tab to the TabCollection.
    return _toolbox.ToolBoxTabs.Add(tabName);
}

_toolbox is correctly set to my EnvDTE.ToolBox instance.

When I activate my add-in in VS, the toolbox tab is created as soon as I open the first document - so far it works as expected. However, there is no toolbox item added to my tab.

After I have reset the toolbox (right click -> reset toolbox) everything works like a charm and the toolbox items appear in my tab when i switch between documents. Thus I have to reset the toolbox each time I start VS to have my add-in working.

Do you have any idea how I could solve this issue? Is there a way to programmatically reset the toolbox?