none
Is it possible to add Dropdown menu to Dynamic menu (Word add ins) ? RRS feed

  • Question

  • Hello,

    I am currently building a Word add-in to help users insert text (business specific) at specific locations in their Word documents.

    The list of text allowed for a document is dynamic and depends on the Word document opened by the user.

    It would work best for me if I can dynamically load the insert text as items in a dropdown.  I have been experimenting with DynamicMenu control, but I am only able to add Button, Checkbox and a few other controls to DynamicMenu.  When I add a Dropdown/Combobox to the DynamicMenu, my 'insert text' does not show up at runtime.

    Ideally, I want the user to pick an 'insert text' from the Dropdown and press a button to insert the text into the document.

    Rgds,

    Suresh

    Thursday, December 15, 2011 12:28 PM

Answers

  • Hi Suresh

    the dropdown and combobox controls share some "get" attributes that let you build the list dynamically, at run-time. The attributes will trigger their callbacks when the Ribbon is loaded and after that, when Ribbon.Invalidate or Ribbon.InvalidateControl is used.

    The attributes of interest for dynamic contents are: getItemCount, getItemID, getItemImage, getItemLabel, getItemScreentip, getItemSupertip

    So you assign callbacks to the attributes you want to use (the first, second and fourth in the list, above, in any case). The number of items is called first, then Item ID for each of the items, then Item Label. The callbacks return the values to the Ribbon in order to build the list.

    Part 1 of the 3-part series on developing using the Ribbon has an example "Filling a Drop-Down List Dynamically".
    http://msdn.microsoft.com/en-us/library/aa338202(office.12).aspx


    Cindy Meister, VSTO/Word MVP
    Thursday, December 15, 2011 2:19 PM
    Moderator

All replies

  • Hi Suresh

    A dropdown cannot be added to a dynamic menu. But a dynamic menu can have sub-menus (fly-outs with more buttons).

    A dropdown can only be placed in a Ribbon Group, but the content of the dropdown can be dynamic.


    Cindy Meister, VSTO/Word MVP
    Thursday, December 15, 2011 12:55 PM
    Moderator
  • For some examples illustrating Cindy's post see:  http://gregmaxey.mvps.org/Dynamic_Ribbon_Menu_Control.htm
    Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm
    Thursday, December 15, 2011 12:59 PM
  • Cindy,

    Thanks for the quick response.  I thought the only way of adding dynamic items (contents/controls) on the Ribbon was though DynamicMenu (using getContent).  I am currently building tags within the getContent method and putting them on the ribbon.

    ex:

    MyStringBuilder.Append(@"<button id=" + "\"" + title + "\"" + " label=" + "\"" + text + "\"" + " onAction="+"\"ActivityButton_Click"+"\""+" />");

    You have mentioned about adding dropdown to a Ribbon Group and adding contents to the dropdown dynamically.  Where do I add code to dynamically load items in the dropdown ?

    Greg,

    I had a look at your site while I started off work on the add-ins.  Found your site very helpful. Thanks.

    Regards

    Suresh

    Thursday, December 15, 2011 2:07 PM
  • Hi Suresh

    the dropdown and combobox controls share some "get" attributes that let you build the list dynamically, at run-time. The attributes will trigger their callbacks when the Ribbon is loaded and after that, when Ribbon.Invalidate or Ribbon.InvalidateControl is used.

    The attributes of interest for dynamic contents are: getItemCount, getItemID, getItemImage, getItemLabel, getItemScreentip, getItemSupertip

    So you assign callbacks to the attributes you want to use (the first, second and fourth in the list, above, in any case). The number of items is called first, then Item ID for each of the items, then Item Label. The callbacks return the values to the Ribbon in order to build the list.

    Part 1 of the 3-part series on developing using the Ribbon has an example "Filling a Drop-Down List Dynamically".
    http://msdn.microsoft.com/en-us/library/aa338202(office.12).aspx


    Cindy Meister, VSTO/Word MVP
    Thursday, December 15, 2011 2:19 PM
    Moderator
  • Cindy,

    Thanks for the detail. That helps a lot.

    Will definitely try it out.

    Regards

    Suresh

    Friday, December 16, 2011 5:52 AM