I am attempting to build some Ribbon Tab Groups programatically.
Getting an error inserting the tool in the group.
Dim Tab1 As RibbonTab = Me.URM_INet.Ribbon.Tabs.Add("Tab1") Dim Group1 As RibbonGroup = New UltraWinToolbars.RibbonGroup("Group1") Group1.Key = "G1" Tab1.Groups.Add("Group1") Group1.Tools.InsertTool(0, "Review Commissions") <----Error "The Tools collection has not been initialized."
what am i missing?
Also, the tools that I want to insert were created in the Infragistics Ribbon Customize screen. Is this the Tools Collection? Tools Base?
How can I create a new tool in that "Tools Collection" using VB?
The problem here is that Group1 is never added to the RibbonTab. You create an instance of a RibbonGroup, then set its Key to a new value, then add a new group to the RibbonTab with the key of "Group1" (the Add method taking a string creates a new RibbonGroup). Group1 still belongs to now RibbonTab, so you cannot add tools to it. Use this code instead:
Dim Tab1 As RibbonTab = Me.URM_INet.Ribbon.Tabs.Add("Tab1")Dim Group1 As RibbonGroup = Tab1.Groups.Add("Group1")Group1.Tools.InsertTool(0, "Review Commissions")
Mike,
Thanks for the code tips. Works great.
I want to know more about creating new tools from code. I assume I would have to add them to the collection before adding them to a group or toolbar button.
That's not exactly true. I believe if you add a tool instance to a menu, toolbar, or ribbon group when there is no root tool, but the code is between BeginInit and EndInit calls on the toolbars manager, the tool instance will automatically be cloned and added as a root tool. Otherwise, you will get an exception. I find the easiest way to make sure you create the tools correctly and have the reference to the correct tool instance is to manually create the root tools when adding them to the manager and to use the AddTool or InsertTool methods of the various tool collections to add instance tools. The AddTool and InsertTool methods will return the instance of the tool added to the menu, toolbar, or ribbon group, and you just have to down cast it if you need to access a property or method on a specific tool type.