How to Add Child Nodes to ObjectExplorer?

Mar 21, 2010 at 6:59 PM

I'm trying to figure out how to add child nodes to a stored procedure node item in the ObjectExplorer.  All the examples I've seen only deal with adding menu items to an existing node.

Below is the code I've seen for getting at the menu handler for a node.  What do I use in place of IMenuHandler for the type when calling GetService()? Do I still cast it to a HierarchyObject?  I've tried many interfaces in the SSMS namespace but I can't find any that seem to work.

Also I'm not sure what event that I would add the child nodes in?  I don't think I want to add them on the SelectionChanged event, more likely the NodesRefreshed or BufferedNodesRefreshed event?

private HierarchyObject _tableMenu;

private void Provider_SelectionChanged(object sender, NodesChangedEventArgs args)
{
            INodeInformation[] nodes;
            int nodeCount;
            
            IObjectExplorerService objectExplorer = ServiceCache.GetObjectExplorer();
            objectExplorer.GetSelectedNodes(out nodeCount, out nodes);
            INodeInformation node = (nodeCount > 0 ? nodes[0] : null);

            if (node.Context == "some context")
            {
                _tableMenu = (HierarchyObject) node.GetService(typeof (IMenuHandler));

                MenuItem item = new MenuItem();
                _tableMenu.AddChild(string.Empty, item);
            }
}

Jan 20, 2011 at 8:17 PM
mmoble wrote:

I'm trying to figure out how to add child nodes to a stored procedure node item in the ObjectExplorer.  All the examples I've seen only deal with adding menu items to an existing node.

Below is the code I've seen for getting at the menu handler for a node.  What do I use in place of IMenuHandler for the type when calling GetService()? Do I still cast it to a HierarchyObject?  I've tried many interfaces in the SSMS namespace but I can't find any that seem to work.

Also I'm not sure what event that I would add the child nodes in?  I don't think I want to add them on the SelectionChanged event, more likely the NodesRefreshed or BufferedNodesRefreshed event?

private HierarchyObject _tableMenu;

private void Provider_SelectionChanged(object sender, NodesChangedEventArgs args)
{
            INodeInformation[] nodes;
            int nodeCount;
            
            IObjectExplorerService objectExplorer = ServiceCache.GetObjectExplorer();
            objectExplorer.GetSelectedNodes(out nodeCount, out nodes);
            INodeInformation node = (nodeCount > 0 ? nodes[0] : null);

            if (node.Context == "some context")
            {
                _tableMenu = (HierarchyObject) node.GetService(typeof (IMenuHandler));

                MenuItem item = new MenuItem();
                _tableMenu.AddChild(string.Empty, item);
            }
}

I'm also trying to figure this out?
Anone has done it?
Thanks