none
RibbonDropDown getItemLabel issue with Excel 2016 RRS feed

  • Question

  • getItemLabel in RibbonDropdown does work fine for excel 2010 and 2013. But when I used the same code for excel 2016, the dropdown is not working. I think the items are not getting loaded.

    As currently I can not debug in the system where excel 2016 is present, Can someone help how to use the same method to work for excel 2016. Or do I need to modify my code?

    Monday, October 31, 2016 12:20 PM

Answers

  • Hi MinaketanBiswal,

    Could you share us your custom ribbon xml and code? I made a test with below xml and code, it works under Excel 2013 and Excel 16.0.7369.2038.

    //Ribbon.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
      <ribbon>
        <tabs>
          <tab idMso="TabAddIns">
            <group id="MyGroup"
                   label="My Group">
              <dropDown id="Sample1" getItemCount="GetCount" getItemLabel="GetLabel" onAction="MyAction"/>
            </group>
          </tab>
        </tabs>
      </ribbon>
    </customUI>
    //Ribbon.cs
            public int GetCount(Office.IRibbonControl Control)
            {
                return 3;
            }
    
            public string GetLabel(Office.IRibbonControl Control, int Index)
            {
                return "Item" + Index.ToString();
            }
            public void MyAction(Office.IRibbonControl Control, string ItemId, int Index)
            {
                MessageBox.Show("OnAction! Item" + Index.ToString() + " has been Selected");
                this.ribbon.InvalidateControl("Sample1");
            }
    

    I suggest you try above xml and code to check whether it will work. If it does, I suggest you compare the difference. If it does not, I suggest you try other controls to check whether it will work.

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, November 2, 2016 8:13 AM

All replies

  • Hello Minaketan,

    Is your add-in loaded in Excel 2016? Did you have a chance to check the COM add-ins list in Excel? Is your add-in listed there as active?

    Microsoft Office applications can disable VSTO Add-ins that behave unexpectedly. If an application does not load your VSTO Add-in, the application might have hard disabled or soft disabled your VSTO Add-in.

    Hard disabling can occur when an VSTO Add-in causes the application to close unexpectedly. It might also occur on your development computer if you stop the debugger while the Startup event handler in your VSTO Add-in is executing.

    Soft disabling can occur when a VSTO Add-in produces an error that does not cause the application to unexpectedly close. For example, an application might soft disable a VSTO Add-in if it throws an unhandled exception while the Startup event handler is executing.

    When you re-enable a soft-disabled VSTO Add-in, the application immediately attempts to load the VSTO Add-in. If the problem that initially caused the application to soft disable the VSTO Add-in has not been fixed, the application will soft disable the VSTO Add-in again. Read more about that in the How to: Re-enable a VSTO Add-in That Has Been Disabled article. 

    Do you get any UI errors?

    By default, if an VSTO Add-in attempts to manipulate the Microsoft Office user interface (UI) and fails, no error message is displayed. However, you can configure Microsoft Office applications to display messages for errors that relate to the UI. You can use these messages to help determine why a custom Ribbon does not appear, or why a Ribbon appears but no controls appear. See How to: Show Add-in User Interface Errors for more information. 


    [custom.development]

    Monday, October 31, 2016 2:25 PM
  • Thanks Eugene for your reply.

    Below are my points.

    Addin got successfully installed in Excel 2016 and is listed in Active section.

    So far I have checked, most of the functionalities related to Ribbon are working fine except the dropdown. Dropdown is not getting expanded. As per my knowledge, normally if dropdown does not have any item, it behaves like that.

    I did not get any error after enabling the User Interface Error in excel.

    After creating one sample code in Visual Studio 2015, I got some ideas. Ribbon dropdown accepts items of type RibbonDropDownItems (does not accept string type). But my current code which is running successfully for excel 2010 and 2013, is using String type items through getItemLabel method.

    Can I use the same code for excel 2016 ?

    Tuesday, November 1, 2016 11:51 AM
  • Hi MinaketanBiswal,

    Could you share us your custom ribbon xml and code? I made a test with below xml and code, it works under Excel 2013 and Excel 16.0.7369.2038.

    //Ribbon.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
      <ribbon>
        <tabs>
          <tab idMso="TabAddIns">
            <group id="MyGroup"
                   label="My Group">
              <dropDown id="Sample1" getItemCount="GetCount" getItemLabel="GetLabel" onAction="MyAction"/>
            </group>
          </tab>
        </tabs>
      </ribbon>
    </customUI>
    //Ribbon.cs
            public int GetCount(Office.IRibbonControl Control)
            {
                return 3;
            }
    
            public string GetLabel(Office.IRibbonControl Control, int Index)
            {
                return "Item" + Index.ToString();
            }
            public void MyAction(Office.IRibbonControl Control, string ItemId, int Index)
            {
                MessageBox.Show("OnAction! Item" + Index.ToString() + " has been Selected");
                this.ribbon.InvalidateControl("Sample1");
            }
    

    I suggest you try above xml and code to check whether it will work. If it does, I suggest you compare the difference. If it does not, I suggest you try other controls to check whether it will work.

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, November 2, 2016 8:13 AM
  • Dear Edward,

    Thanks for the response and it helped me to solve my issue.

    Actually my existing code is similar to the code that you provided. From here I came to the conclusion that code is correct. I was not getting any dropdown items while the control was being loaded. After getting data I reloaded the control through Ribbon.InvalidateControl () method and it worked fine.

    But here I found one difference in Excel 2016. 

    In excel 2013 and prior version, after clicking login button the dropdown was being loaded with the items coming from DB (In Ribbon.xml file dropdown is present before the login button).

    But now in excel 2016, the dropdown control methods (getCount, getItemLabel etc. ) are being called before the login button getting clicked resulting no data. So I used Ribbon.InvalidateControl () to reload it.

    Thanks,

    Minaketan

    Thursday, November 3, 2016 9:58 AM