none
Dynamically add RibbonGroup and controls at runtime RRS feed

  • Question

  • Hello all,

    Now I know this question has been tossed around a few times, some in this forum itself but I haven't found a satisfactory answer to it that matches my requirement.

    Here's my scenario. I have a VSTO C# 4.0 Excel application. I need to add a RibbonGroup to some of the tabs and then a couple of controls to the RibbonGroup, conditionally, after the application has loaded. Can anyone point me in the right direction? Sample working code will be much appreciated.

    Thanks,


    Vishal Trivedi http://blog.vishaltrivedi.com/
    Friday, May 20, 2011 4:48 AM

Answers

All replies

  • Hi Vishal

    Create all the tabs and groups in your Ribbon XML and set the Visible attribute to False. If the conditions are met, use the getVisible callback to make them visible, as required.


    Cindy Meister, VSTO/Word MVP
    Friday, May 20, 2011 4:32 PM
    Moderator
  • Thanks for the reply Cindy, I can try this approach.

    However, can we not create these controls at runtime? I would certainly prefer it that way.

    Thanks,


    Vishal Trivedi http://blog.vishaltrivedi.com/
    Friday, May 20, 2011 6:30 PM
  • Hi,

    Check out this thread: http://social.msdn.microsoft.com/Forums/en-US/officegeneral/thread/e0bf57d8-711c-4f00-ade6-7c5f222c8833

    Regards,

    Mauro


    twitter.com/mcastagnasso | castagnasso.wordpress.com | If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Friday, May 20, 2011 8:18 PM
  • Thanks for the reply Cindy, I can try this approach.

    However, can we not create these controls at runtime? I would certainly prefer it that way.

    Thanks,


    Vishal Trivedi http://blog.vishaltrivedi.com/


    Hi Vishal,

    Any update?


    Best Regards, Calvin Gao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, May 26, 2011 12:37 PM
    Moderator
  • Hello all,

    Sorry for the late update.

    I cannot create the RibbonGroups and their rrespective buttons in advance as it will be decided during runtime which groups and buttons are to be added. For this reason I cannot follow Cindy's approach mentioned above.

    I'll try the approach suggested by Mauro and update this thread tomorrow.

    Thanks,

     


    Vishal Trivedi http://blog.vishaltrivedi.com/
    Thursday, May 26, 2011 4:08 PM
  • Hi Vishal,

    Did you solve the issue?

    Regards,

    Mauro


    twitter.com/mcastagnasso | castagnasso.wordpress.com | If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Wednesday, June 1, 2011 2:39 AM
  • Hello Everyone,

    As per Mauro's suggestion, I tried to do this by following the code example at the below URL but it did not work.
    http://rugicon.codeplex.com/SourceControl/changeset/view/71355#1431439

    Below is my code:

    var rbTemp = this.Factory.CreateRibbonButton();
    
    rbTemp.Name = "rbtnTemp";
    rbTemp.ControlSize = Office.RibbonControlSize.RibbonControlSizeLarge;
    rbTemp.Description = "I was created dynamically...";
    rbTemp.Label = "I was created dynamically...";
    rbTemp.ScreenTip = "I was created dynamically...";
    
    this.grpTemp.Items.Add((RibbonButton) rbTemp);
    
    

    I'm getting the below error on the last line of code:
    Collection is read only. Cannot change content of the collection.

    I don't know where I'm going wrong, but no issue is not solved yet.

    Thanks,


    Vishal Trivedi http://blog.vishaltrivedi.com/
    Thursday, June 2, 2011 5:15 AM
  • Hello,

    Are you creating the buttons inside the Ribbon constructor? I mean, the class constructor.

    Regards,

    Mauro


    twitter.com/mcastagnasso | castagnasso.wordpress.com | If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Friday, June 3, 2011 2:11 AM
  • No I wasn't, I had this code in the Load event of the ribbon. I just moved it to the constructor and it worked!

    Thanks a lot Mauro, problem solved! :-)


    Vishal Trivedi http://blog.vishaltrivedi.com/
    Friday, June 3, 2011 2:57 PM