Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
25
Adding sub menu with buttons to UltraToolBarManager at runtime
posted

Hi.

I’m trying to add a sub menu with buttons to an UltraToolBarManager at run time.

The error is on Sub Menu1 on the step 8 because I can’t add the button to the Sub Menu once he was already instantiated on step 6.

Note: I need to do this way, because I’m reading the metadata from a text file in order to build the menus at run time.

I appreciate your help.

Best Regards

Mário

Here is a code sample.

       '------------------------------------------------------'

        ' Main Menu

        '------------------------------------------------------'

        Dim menu1 As New PopupMenuTool("Tabelas")

        menu1.SharedProps.Caption = "Tabelas"

        Me.UltraToolbarsManager1.Tools.Add(menu1)

        '------------------------------------------------------'

        ' SubMenu1 (Cant add a button)

        '------------------------------------------------------'

        ' 1- Instantiates the sub menu

        ' 2 – Adds the sub menu to the toolbar  

        Me.UltraToolbarsManager1.Tools.Add(New PopupMenuTool("submenu1"))

        ' 3 – Adds a caption to the Sub Menu

        Me.UltraToolbarsManager1.Tools("submenu1").SharedProps.Caption = "Sub-menu1"

        ' 4 – Adds the Sub Menu to the Main Memu

        menu1.Tools.AddTool("submenu1")

 

        ' 5 – Instantiates the button

        ' 6 – Adds the button to the ToolBar

        Me.UltraToolbarsManager1.Tools.Add(New ButtonTool("button4"))

        ' 7 – Adds caption to button

        Me.UltraToolbarsManager1.Tools("button4").SharedProps.Caption = "Botão 4"

 

         8 – Adds button to the Sub Menu

        menu1.Tools("submenu1").ToolbarsManager.Tools.Add(Me.UltraToolbarsManager1.Tools("button4"))

 

        '------------------------------------------------------'

        ' SubMenu2 (OK)

        '------------------------------------------------------'

 

        ' 1- Instantiates the sub menu

        Dim submenu2 As New PopupMenuTool("submenu2")

        ' 2 - Adds Sub menu to toolbar

        UltraToolbarsManager1.Tools.Add(submenu2)

        ' 3 - Adds  caption to Sub Menu

        submenu2.SharedProps.Caption = "Sub-menu2"

        ' 4 - Adds Sub Menu to the main

        menu1.Tools.AddTool("submenu2")

        ' 5 - Instantiates the button

        Dim button5 As New ButtonTool("button5")

        ' 6 - Adds button to ToolBar

        UltraToolbarsManager1.Tools.Add(button5)

        ' 7 - Adds caption to button

        button5.SharedProps.Caption = "button-5"

        ' 8 - Adds button to Sub Menu 2

        submenu2.Tools.Add(button5)

 

        '-----------------------------------------------------

 

        ' Adds the menu to the toolbar

        Me.UltraToolbarsManager1.Toolbars("UlToolB").Tools.AddTool("Tabelas")

Parents
No Data
Reply
  • 6158
    Suggested Answer
    Offline posted

    Hello Mario,

    The code for step 8 (for SubMenu1) is accessing a Tools collection via the ToolbarsManager property on the SubMenu1 tool. This ToolbarsManager property is a backward pointer to the main UltraToolbarsManager, and thus this code is attempting to add the tool to the root Tools collection. To learn more about Instance and Root tools, you can look at this help article.

    In your case,  you want to add the new tool to the Tools collection for the SubMenu1 tool. You are accessing the SubMenu1 tool by indexing into the menu1's Tools collection which will return the tool as type ToolBase. You need to cast the tool returned from menu1.Tools("submenu1") to type PopupMenuTool in order to have access to it's Tools collection.

    Let me know if you have any further questions.

    Chris

Children