ExcelDNA ribbons with dynamic menu and checkboxes

1,321 views
Skip to first unread message

zohrehta...@gmail.com

unread,
Sep 9, 2014, 5:26:25 AM9/9/14
to exce...@googlegroups.com
Hi all,
I am trying to create a dynamic menu using ExcelDNA ribbons which contains checkboxes such that the user can make a multiple selections of the dynamically created choices, and then execute an action on all the choices. Any idea if that can be achieved please?

Govert van Drimmelen

unread,
Sep 9, 2014, 6:39:31 AM9/9/14
to exce...@googlegroups.com
Hi,

That shouldn't be a problem.

A good start is the three-part series here: http://msdn.microsoft.com/en-us/library/aa338202(office.12).aspx

You need to keep in mind that the Ribbon on;y works with callbacks, so to update the list of choices in a list, you need to get Excel to refresh your control (or the whole Ribbon extension). For this you set an onLoad callback (on the customUI element) and in your handler code keep hold of the IRibbonUI interface passed in. This interface has two methods - Invalidate and InvalidateControl - which you call when a control should be refreshed. 

-Govert

zohrehta...@gmail.com

unread,
Sep 9, 2014, 9:51:10 AM9/9/14
to exce...@googlegroups.com
Thanks very much for the quick reply. In fact I have encountered a couple of problems. 
I am planning to have a splitButton containing a button and a dynamic menu. But when I was trying to include the dynamic menu as part of the splitButton I get errors saying that just a menu can be part of a splitBottom. Is this the case? So now I have created a splitButton with a menu which contains a dynamic menu as following:

<splitButton id='SplitButtonCheckBoxRefresh' size='large' >
                <button id='ButtonCheckBoxRefresh' label='Refresh Using Check Boxes' image='Load' onAction='RunTagMacro' tag='RefreshAll' />
                <menu id='MenuCheckBoxRefresh' label='Menu' >
                  <dynamicMenu id="DynamicCheckBoxRefresh" label="Select Curves"
                              getContent="OnGetContent_CheckBox"
                              invalidateContentOnDrop="true"
                              />
                </menu>
              </splitButton>

with the c# code as:
public string OnGetContent_CheckBox(IRibbonControl control)
        {

            var context = AddIn.Bootstrapper.Container.Resolve<ExcelContext>();
            var curvesByKey = context.CurvesByKey;
     
            string stCheckBox = "<menu xmlns='http://schemas.microsoft.com/office/2006/01/customui' itemSize='large'>";
            foreach (var item in curvesByKey)
            {    
        
                stCheckBox += "<checkBox id='curve" + Guid.NewGuid().ToString() + "\' label= '" + item.Value.CurveName + "'/>";
            }
            stCheckBox += "</menu>";
            return stCheckBox;
        }

Now two question please?
1) Can dynamic menu be directly part of splitButton?
2) More important question: The Check boxes i get in my ribbon look and behave like buttons and not check boxes. I can not tick and select multiple choices and operate an action on them?

Many thanks.

Govert van Drimmelen

unread,
Sep 9, 2014, 11:40:27 AM9/9/14
to exce...@googlegroups.com
I think you're right that a splitButton cannot contain a dynamicMenu - it seems from here: http://msdn.microsoft.com/en-us/library/dd950671(v=office.12).aspx
that the splitButton can contain only button. menu, or toggleButton.

I don't know about your more important question about the checkBoxes in the dynamicMenu - maybe you should ask on the Excel for Developers forum here: http://social.msdn.microsoft.com/Forums/office/en-US/home?forum=exceldev

-Govert
Reply all
Reply to author
Forward
0 new messages