Not able to collapse Root Node under Server Explorer Hierarchy

Soumabha Sarkar 41 Reputation points
2022-11-18T14:40:24.6+00:00

We have a our custom hierarchy that we are showing in Visual Studio Server Explorer as a part of our extension. We are adding root node in the hierarchy like below (pseudo code)

class VsMyHierarchy : IVsUIHierarchy, IOleCommandTarget, IDisposable  
{  
 private EventSinkCollection hierarchyEventSinks = new EventSinkCollection();  
 internal void Initialize()  
 {  
 imageList = GetImageList();  
  
 //Add the root node  
 AccountsNode rootNode = new AccountsNode(null);  
 rootNode .Caption = "ROOT ACCOUNTS";  
 rootNode.Hierarchy = this;  
 rootNode.ItemId = VSConstants.VSITEMID_ROOT;  
 rootNode.PopulateItem();  
 }  
  
 internal void AddNodeToHierarchy(VsNode node, bool fNotify)  
 {  
   if (this != node.Hierarchy)  
 node.Hierarchy = this;  
  
   if (fNotify)  
   {  
 uint itemidParent = (uint)VSConstants.VSITEMID_NIL;  
 uint itemidSiblingPrev = (uint)VSConstants.VSITEMID_NIL;  
 uint itemidAdded = node.ItemId;  
  
 HierEvts_OnItemAdded(itemidParent, itemidSiblingPrev, itemidAdded);  
   }  
 }  
  
 private void HierEvts_OnItemAdded(uint itemidParent, uint itemidSiblingPrev, uint itemidAdded)  
 {  
   foreach (IVsHierarchyEvents sink in hierarchyEventSinks)  
   {  
 sink.OnItemAdded(itemidParent, itemidSiblingPrev, itemidAdded);  
   }  
 }  
  
 public virtual int AdviseHierarchyEvents(IVsHierarchyEvents pEventSink, out uint pdwCookie)  
 {  
   pdwCookie = hierarchyEventSinks.Add(pEventSink) + 1;  
   return VSConstants.S_OK;  
 }  
}  

The class of Accounts and Account node is like below (pseudo code)

class AccountsNode : VsNode  
{  
 void PopulateItem()  
 {  
 var accountNode1 = new AccountNode();  
 accountNode1.ItemId = 0;  
 accountNode1.Hierarchy.AddNodeToHierarchy(accountNode1,true);  
 }  
}  
  
class AccountNode : VsNode  
{  
 // Code for AccountNode  
}  
  
class VsNode  
{  
 // Code for VsNode  
}  

We are adding the hierarchy in Server Explorer using IVsUIHierarchyWindow.AddUIHierarchy. We can expand the root node "ROOT ACCOUNTS" but we are not able to collapse it. We have added nodes inside Child Node under Root Node and we can expand and collapse it without any issue. Only issue is with the ROOT Node.

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,578 questions
Visual Studio Debugging
Visual Studio Debugging
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Debugging: The act or process of detecting, locating, and correcting logical or syntactical errors in a program or malfunctions in hardware. In hardware contexts, the term troubleshoot is the term more frequently used, especially if the problem is major.
935 questions
{count} votes