Ryan, wrote a great article on how to use a module to hide a toolbar item at runtime here. I wanted to expand his article slightly to show how a similar technique could be used to hide a context menu.
The main difference is what workspace the context menu exists in. In Ryan’s example he uses the ToolbarWorkspace, where the Context menus reside in the NavWorkspace.
Lets look at the code needed to hide the Insert Account/Contact context menu from the Account context menu group:
NavWorkspace navbar = _parentWorkItem.Workspaces["NavBar"] as NavWorkspace; if (navbar == null) return; IMenuService navmenusvc = toolbar.WorkItem.Services.Get<IMenuService>(); if (navmenusvc == null) return; NavItemCollection navcol2 = (NavItemCollection)menusvc.FindMenu("contextAccount") as NavItemCollection; if (navcol2 != null) { navcol2.RemoveItem("menuItemNewContactAccount"); } |




Andrew you are using FindMenu? I don’t have access right now to check but I am pretty sure that is not the right method to find a button?