Export (0) Print
Expand All
0 out of 1 rated this helpful - Rate this topic

How to: Control Solution Explorer

Solution Explorer is a tool window in the Visual Studio integrated development environment (IDE) that displays the contents of a solution, which includes the solution's projects and each project's items. Like other tool windows in Visual Studio, you can control its physical parameters, such as size, location, and whether it is docked or free-floating. For information about how to manipulate this tool window as well as other Visual Studio tool windows, see How to: Change Window Characteristics.

Solution Explorer does not have its own automation objects as such, but you can control the contents of its hierarchy to a certain extent by using UIHierarchy. To control projects and project items in the solution, use the project automation model. For more information, see Controlling Projects and Solutions.

NoteNote

The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. These procedures were developed with the General Development Settings active. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.

To control Solution Explorer by using UIHierarchy

  1. If Solution Explorer is not already visible, click Solution Explorer on the View menu.

  2. Open a project that has a large number of elements, such as an Add-in project.

  3. In Solution Explorer, click a node that has at least two sub-nodes.

  4. Run the following code.

This example demonstrates how to manipulate Solution Explorer by using UIHierarchy.

using System.Text;
using EnvDTE;
using EnvDTE80;
using EnvDTE90;
using EnvDTE100;public void OnConnection(object application, ext_ConnectMode 
  connectMode, object addInInst, ref Array custom)
{
    _applicationObject = (DTE2)application;
    _addInInstance = (AddIn)addInInst;
    // Pass the applicationObject member variable to the code example.
    slnExplUIHierarchyExample(_applicationObject);
}

public void slnExplUIHierarchyExample(DTE2 dte)
{
    UIHierarchy UIH = dte.ToolWindows.SolutionExplorer;
    // Requires a reference to System.Text.
    // Set a reference to the first level nodes in Solution Explorer. 
    // Automation collections are one-based.
    UIHierarchyItem UIHItem = UIH.UIHierarchyItems.Item(1);
    StringBuilder sb = new StringBuilder();

    // Iterate through first level nodes.
    foreach ( UIHierarchyItem fid in UIHItem.UIHierarchyItems )
    {
        sb.AppendLine(fid.Name);
        // Iterate through second level nodes (if they exist).
        foreach ( UIHierarchyItem subitem in fid.UIHierarchyItems )
        {
            sb.AppendLine("   "+subitem.Name);
            // Iterate through third level nodes (if they exist).
            foreach ( UIHierarchyItem subSubItem in 
              subitem.UIHierarchyItems )
            {
                sb.AppendLine("        "+subSubItem.Name);
            }
        }
    }
    System.Windows.Forms.MessageBox.Show(sb.ToString());
}
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.