How to add submenu to C1Menu at runtyme??

Posted by: warrenw on 10 September 2017, 11:31 am EST

  • Posted 10 September 2017, 11:31 am EST

    Hello,


    I have seen code examples for adding the menus at runtime but this was with the C1WebMenu control.It has now been replaced with the C1Menu control. How can I add a submenu?


    I know how to add an item to the root right now as shown below:


     


     


     



     



     


    Dim item1 As New C1MenuItem

    item1.Text =



    "Item 1"



     



     


    'add item 1 to the main menu bar



    C1Menu2.Items.Add(item1)


    Thanks!!!!


     


  • Replied 10 September 2017, 11:31 am EST

    Hi,Warren,


    Please try to use the code below:



            C1MenuItem rootMenuItem = new C1MenuItem();
            rootMenuItem.Text = "rootMenuItem";
            C1MenuItem subMenuItem = new C1MenuItem();
            subMenuItem.Text = "subMenuItem";
            rootMenuItem.Items.Add(subMenuItem);
            C1Menu1.Items.Add(rootMenuItem);

            C1MenuItem subMenuItem2 = new C1MenuItem();
            subMenuItem2.Text = "subMenuItem2";
            C1Menu1.Items[C1Menu1.Items.Count - 1].Items.Add(subMenuItem2);

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels