locked
Adding Buttons to RibbonGroup items Dynamically RRS feed

  • Question

  • Hi,

    I want to know wether its possible to add Toggle Buttons or any other Ribbon Cotrol to RibbonGroup Dynamically.
    Also i need to remove items if there are already items in it.

    RibbonToggleButton rtb = new RibbonToggleButton();

    rtb.ControlSize = Microsoft.Office.Core.RibbonControlSize.RibbonControlSizeLarge;

    rtb.Image = global::ExcelAddIn1.Properties.Resources.MyStocks;

    rtb.Label = text;

    rtb.ShowImage = true;

    myGroup.Items.Add(rtb)



    this code did not  work. Error was 'collection is read only'.
    Is there another way to this without an error.


    Thanks
    Pati

    Tuesday, October 14, 2008 4:56 AM

Answers

  •  Hello,

    There are two ways to address your scenario:

    A) Design the Ribbon up front and then show and hide the controls at run time.

    B) Add controls to a dynamic menu. You can add and remove controls from a dynamic menu at run time. The following walkthrough example does this very thing - Walkthrough: Updating the Controls on a Ribbon at Run Time.

    C) If you only need to make the decision when a workbook is initially opened, you can create two separate Ribbons in your project and then load the appropriate Ribbon when the workbook opens. You can do this in the CreateRibbonExtensibilityObject method of the ThisAddin or ThisWorkbook class of your project.  For more information about this approach, see the topic Ribbon Overview.

    Norm E.
    Norm Estabrook
    • Proposed as answer by Mary Lee - MSFT Tuesday, October 14, 2008 6:02 PM
    • Marked as answer by Tim Li Tuesday, October 21, 2008 6:53 AM
    Tuesday, October 14, 2008 5:03 PM
    Answerer

All replies

  • The Ribbon does not support adding or removing controls dynamically. However, you can hide and show existing controls in your group in order to give the desired look and feel.

    This only works for your selfmade groups. It does not work for built-in groups.

    HTH
    Birgit

    Tuesday, October 14, 2008 6:41 AM
  •  Hello,

    There are two ways to address your scenario:

    A) Design the Ribbon up front and then show and hide the controls at run time.

    B) Add controls to a dynamic menu. You can add and remove controls from a dynamic menu at run time. The following walkthrough example does this very thing - Walkthrough: Updating the Controls on a Ribbon at Run Time.

    C) If you only need to make the decision when a workbook is initially opened, you can create two separate Ribbons in your project and then load the appropriate Ribbon when the workbook opens. You can do this in the CreateRibbonExtensibilityObject method of the ThisAddin or ThisWorkbook class of your project.  For more information about this approach, see the topic Ribbon Overview.

    Norm E.
    Norm Estabrook
    • Proposed as answer by Mary Lee - MSFT Tuesday, October 14, 2008 6:02 PM
    • Marked as answer by Tim Li Tuesday, October 21, 2008 6:53 AM
    Tuesday, October 14, 2008 5:03 PM
    Answerer