none
dynamicMenu in contextMenu invalidates on drop, even if invalidateContentOnDrop is set to "false"? RRS feed

  • Question

  • Hi people,

    I've only tested this on Excel 2010, but I'll post it in the General forum, as I think it probably pertains to customUI XML and not just one application.

    When I create a dynamicMenu in the ribbon, as shown below, everything works correctly:

    <group id="TestTab" label="Test tab">

             <dynamicMenu id="MyDynamicMenu" label="My Dynamic Menu" getContent="getContentMacro"  />

    </group>

    I can also add the invalidateContentOnDrop="true" attribute, and it will correctly generate the menu each time it is accessed.

    However, when I create a dynamicMenu in a contextMenu, as shown below, it seems to invalidate each time the menu drops, regardless of whether I set invalidateContentOnDrop="false":

    <contextMenu idMso="ContextMenuCell">

             <dynamicMenu id="MyDynamicMenu" label= "My Dynamic Menu" getContent="getContentMacro" insertBeforeMso="Cut"/>

    </contextMenu>

    Is this "working as intended" or am I making a mistake?

    Thanks

    Ray

    Tuesday, May 27, 2014 12:08 PM

All replies

  • I found a workaround for the dynamicMenu, but I'd still like to know if this is a bug or a feature. ;-)

    When I build the XML for the dynamicMenu the first time around with getContent, I store the XML in a module-level string variable called strXML.

    Each time getContent fires, I check to see if there is anything already stored in strXML. If so, i load the XML from there into returnedVal and I'm done.

    Thursday, May 29, 2014 11:44 AM
  • Hi Ray Culp,

    Please take a look at this document, and focus on the dynamicMenu:

    http://msdn.microsoft.com/en-us/library/gg469862(v=office.14).aspx#odc_xl_ta_CustomExcelContextMenus_CustomizingContextMenus

    I tested according to the xml in this document:

    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
       <contextMenus>
          <contextMenu idMso="ContextMenuCell">
             <dynamicMenu id="MyDynamicMenu" 
                label= "My Dynamic Menu" imageMso="HappyFace" 
                getContent="GetContent" insertBeforeMso="Cut"/>
          </contextMenu>
       </contextMenus>
    </customUI>
    I'm using Office 2013, and looks like I can't reproduce your problem. The custom dynamic menu will show up each time I right click on the cells. I suspect that there could be some problems with other part of the customUI xml. If something goes wrong with some of the xml nodes, some custom menus will disappear. I recommend you validate the xml in Custom UI Editor for Microsoft Office before saving the xml.

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, May 29, 2014 4:17 PM
    Moderator
  • Dear Caillen,

    Thanks for your reply.

    I've been validating the static XML embedded in the project using the Custom UI Editor, but not the dynamically generated XML. There is probably an error in there that I didn't detect. I'll check this and post my results.

    Thanks

    Ray

    Friday, May 30, 2014 10:22 PM
  • Hi Caillen,

    Ok, so I downloaded a pristine copy of Ron de Bruin's dynamicMenu / contextMenu examples from here: http://www.rondebruin.nl/win/winfiles/ContextMenu2010-2013.zip

    Just to make sure we are on the same page, I'm testing this with Excel 2010. ;-)

    The behavior is exactly as I described in my first post. Each time you click on the dynamicMenu, the getContent macro is fired - not just the first time.

    If you insert a Stop statement at the top of the getContent macro, you can verify that it is fired every time you click the dynamicMenu.

    If you let the getContent macro run one time, but then bail out the second time by inserting an Exit Sub statement right after the Stop statement, then the dynamicMenu will be empty.

    Maybe I am not using the right technical term when I say that the XML is invalidated, but the effect is that the dynamicMenu does not remember from one click to the next what its contents are.

    I don't see this happening with dynamicMenus in the ribbon, only in contextMenus.

    Like I mentioned earlier, it isn't a big deal. I just let getContent create the XML once and then store the XML in a module-level variable. The next time getContent fires, I check to see if there is already XML and if so, I retrieve it. ;-)

    Thanks

    Ray

    Friday, May 30, 2014 11:01 PM
  • I was thinking about this over the weekend.

    I only see four possible reasons for this behavior.

    1. Ron de Bruin and I made the same mistake in our code (can be solved by both of us correcting our mistakes).
    2. There is something wrong with my particular installation of Excel (can be solved by me re-installing Excel).
    3. This is a bug (can only be solved by Microsoft).
    4. This is a feature (doesn't need to be solved). ;-)
    Tuesday, June 3, 2014 12:27 PM