locked
Visual Studio Package: Expand/Collpase State of Items RRS feed

  • Question

  • Hi there,

    I want to manipulate the expand/collapse state of TreeView items in the solution explorer in my package.

    I want to save the current state, do some stuff with the projects and items (for example delete and readd) and then set the previous expand/collapse state so that the states are as they were before my manipulation.

    Is there an easy way to do this? I think I need another way of doing this as I did before to get project and item data.

    Thx,
    Fabian


    The Visual Studio Settings-Switcher! Visit http://visualstudiogallery.msdn.microsoft.com/a79072f7-3109-44a0-95c0-9c50e729d6a3

    Saturday, October 4, 2014 9:49 AM

All replies

  • Hi again,

    I think I can access the TreeView node via this code:

    UIHierarchy UIH = dte.ToolWindows.SolutionExplorer;
    UIHierarchyItem UIHItem = UIH.GetItem("Node of project with full path");

    But I need the complete path for the specific project node. Is there a way to get this path without calculating it manually? This would save me a lot of time.

    Thanks and bye,
    Fabian





    The Visual Studio Settings-Switcher! Visit http://visualstudiogallery.msdn.microsoft.com/a79072f7-3109-44a0-95c0-9c50e729d6a3

    Sunday, October 5, 2014 3:34 PM
  • Hi Fabian,

    Given that you are already using a package, it would be better to use native IVsHierarchy instead of the automation model (UIHierarchy). See for example these articles (although they are for add-ins):

    HOWTO: Get the IVsHierarchy and Item Id of EnvDTE.Project and EnvDTE.ProjectItem
    http://www.mztools.com/articles/2014/MZ2014006.aspx

    HOWTO: Navigate the files of a solution using the IVsHierarchy interface from an add-in.
    http://www.mztools.com/articles/2014/MZ2014007.aspx

    I don't know what you want to use as input data to get a node, but if you are using an EnvDTE.Project notice that its Project.UniqueName can be used (AFAIK) as canonical name to when calling IVsHierarchy.ParseCanonicalName to get the node id.

    Then you can use IVsHierarchy.GetProperty and IVsHierarchy.SetProperty with the VSHPROPID_Expanded property.


    * My new blog about VSX: http://www.visualstudioextensibility.com * Twitter: https://twitter.com/VSExtensibility * MZ-Tools productivity extension for Visual Studio: http://www.mztools.com.

    Tuesday, October 7, 2014 8:05 AM
  • Hi Carlos,

    oh cool. Many thanks. To get this information directly on a hierarchy instance is a great way.

    But I have problems to implement this behavior. I tried the following code:

    object isExpanded = false;
    ErrorHandler.ThrowOnFailure(hierarchy.GetProperty(projectItemId,
        (int)__VSHPROPID.VSHPROPID_Expanded, out isExpanded));

    The hierarchy instance and the project id are the ones of my project I want to expand.

    But I just get an NotImplementedException. What am I missing?

    Thanks,
    Fabian


    The Visual Studio Settings-Switcher! Visit http://visualstudiogallery.msdn.microsoft.com/a79072f7-3109-44a0-95c0-9c50e729d6a3

    Tuesday, October 7, 2014 6:57 PM