Hi,even though I pass only MenuUID Iam not able to add the item to context menu.Thanks,Uday
private void AddCommandItem() { object Missing = Type.Missing; IDocument ThisDoc = m_MxDoc as IDocument; ICommandBars CommandBars = ThisDoc.CommandBars as ICommandBars; UID CustomCommandUID = new UID(){ Value = "SomeClassLibrary.SomeCommand" }; UID MenuUID = new UID(){ Value = "esriArcMapUI.FeatureLayerContextMenu" }; ICommandBar FeatureLayerContextMenu = CommandBars.Find(MenuUID, false, false) as ICommandBar; FeatureLayerContextMenu.Add(CustomCommandUID, ref Missing); }
private void AddCommandItem() { object Missing = Type.Missing; IDocument ThisDoc = m_MxDoc as IDocument; ICommandBars CommandBars = ThisDoc.CommandBars as ICommandBars; UID CustomCommandUID = new UID(){ Value = "esriArcMapUI.ZoomToSelectedCommand" }; UID MenuUID = new UID(){ Value = "esriArcMapUI.FeatureLayerContextMenu" }; ICommandBar FeatureLayerContextMenu = CommandBars.Find(MenuUID, false, false) as ICommandBar; FeatureLayerContextMenu.Add(CustomCommandUID, ref Missing); }
I think that the first parameter to the Find method should be just the UID object, like ICommandBar FeatureLayerContextMenu = CommandBars.Find(MenuUID, false, false) as ICommandBar; For some reason, when you are trying to get a handle to the feature layer context menu, you are using the value of the UID in the Find method. All of your other calls to the Find method use the UID itself.
ICommandBar FeatureLayerContextMenu = CommandBars.Find(MenuUID, false, false) as ICommandBar;
ICommandBar FeatureLayerContextMenu = CommandBars.Find(MenuUID.Value, false, false) as ICommandBar;
Do you have a requirement to only do this with code? If not you can simply do the following:- open the Customize dialog, under the Toolbars tab select Context Menus- click the Context Menus drop down and scroll to "Feature Layer Context Menu"- you can click and drag commands or tools from the commands tab directly to the desired menu
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.