AnsweredAssumed Answered

programmatically add an item into an ArcMap 10 out-of-box context menu?

Question asked by huangs3 on Jun 21, 2012
Latest reply on Jun 22, 2012 by huangs3
Hi Everybody:

    I ran the following code to add a command into the Data View Context Menu (the one that pops up after right clicking the map data view, as attached picture) of ArcMap. The command with the icon was added to the menu, but once I run this command after that I will get an exception.
    If I do the samething manually by "Customize"==>"Customize Mode" and then drag-drop the command into the "Context Menus" in "Toolbars" tab, then the command will still work fine.
    What is wrong in my code? Thank you!

UID contextMenuId = new UIDClass(); Object optionalIndex = Type.Missing; contextMenuId.Value = "{3846A5B5-D3F8-44CB-BFA3-A5C30F4E535F}"; //the data view context menu ICommandBar commandBar = _mApplication.Document.CommandBars.Find(contextMenuId) as ICommandBar; contextMenuId.Value = "esriArcMapUI.ZoomInFixedCommand"; commandBar.Add(contextMenuId, ref optionalIndex);