Search code examples
visual-studiovisual-studio-extensionsenvdtesolution-explorervisual-studio-automation

Programmatically accessing Visual Studio Solution Explorer search box


I am working on a VS extension that needs to select a specific project in the solution. However, if the user has previously typed any text in the solution explorer search box, when I find the project item, calling

.Select(vsUISelectionType.vsUISelectionTypeSelect)

on it does not work. My idea is to access the search box and clear it before selecting the project. Unfortunatelly, I was not able to find any clue on how to do that, not in documentation and tutorials, not even inspecting the

dte.ToolWindows.SolutionExplorer

object. Am I doing it wrong so I can't find a solution for something that should be more than easy to do?

Thank you in advance, any ideas/help would be appreciated!


Solution

  • To clear the search box:

    IVsSolutionUIHierarchyWindow solutionWindows = (IVsSolutionUIHierarchyWindow)VsShellUtilities.GetUIHierarchyWindow(this.ServiceProvider, VSConstants.StandardToolWindows.SolutionExplorer);    
    
    if (solutionWindows is IVsWindowSearch)
    {
        var slw = solutionWindows as IVsWindowSearch;
        slw.ClearSearch();
    }