I'm working on an addin for Visual Studio 2008 and want to add a permanent submenu to contain my context-sensitive commands to several context menus (such as "Project", "Item", ...).
I have had no problem adding this submenu to the top of the context menu or to the bottom of it. I'm using:
mPlugin.Commands.AddCommandBar(_MenuName, vsCommandBarType.vsCommandBarTypeMenu, commandBar, desiredSubmenuPosition); /*desiredSubmenuPosition = 1 or desiredSubmenuPosition = commandBar.Controls.Count+1 work perfectly fine.
However, I want to add my submenu right before the last separator of the context menu. To do this, I find all the controls that have BeginGroup to true and get the control that has the biggest Index. I then add my submenu to the found index-1 with the above method. But there is something wrong. For some context menus it works fine, for others it creates my submenu at the wrong place (I'm pretty sure I find the right index for insertion...).
Is there a proper way of doing this?