Creating a menu when my application is executing !!!

Hello, I need to create a menu, when my application is executing and this menu must take the name of the options from a table SQLSERVER2005.

Can anyone help me

Thanks


Answer this question

Creating a menu when my application is executing !!!

  • Manana_Man

    Hello, the first code is working very god, but I have another problem. This code is god for a menu like this:
    File-Save
          -Open
    .
    .
    .

    But if I like this menu:
    File-Operations-Save
                           -Open
    File-Print-With Filter
                  -All
    File-Close
    .
    .
    .

    I dont know how  I can do this :(

    Thank you

  • Patrick Sasky

    Just modify this as needed:




    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

            Dim dynamicMenu As New MenuStrip
            Dim menuItemParent As ToolStripMenuItem

            menuItemParent = New ToolStripMenuItem("MenuParent")
            dynamicMenu.Items.Add(menuItemParent)

            menuItemParent.DropDownItems.Add("MyMenu2", Nothing, AddressOf HandleMenuClick)
            menuItemParent.DropDownItems.Add("MyMenu3", Nothing, AddressOf HandleMenuClick)
            menuItemParent.DropDownItems.Add("MyMenu4", Nothing, AddressOf HandleMenuClick)
            menuItemParent.DropDownItems.Add("MyMenu5", Nothing, AddressOf HandleMenuClick)

            Me.Controls.Add(dynamicMenu)

        End Sub

        Private Sub HandleMenuClick(ByVal sender As Object, ByVal e As EventArgs)

            Dim item As ToolStripMenuItem = DirectCast(sender, ToolStripMenuItem)

            MessageBox.Show(item.Text, "Menu Click", MessageBoxButtons.OK, MessageBoxIcon.Information)

        End Sub



     





  • Sam Spencer

    Pls, only one question:
    Can I change the "menuItemParent." for an other in executing time, like: "strParent.DropMenuItems.Add(......)", where strParent is a variable.

    Thnaks.  

  • Rick Taylor

    Thanks, this weekend I try this Smile

  • Dinhduy Tran

    THANKS !!!!!!!!!! Smile

  • Gabriel 06

    Your variable should be a ToolStripMenuItem, not a string. You can always change what the menu is displaying by using:




        menuItemParent.Text = "new text here"


     


    If you need to keep multiple dynamic menus, you can use an array or use generics in 2005:




        Dim myMenus As New List(Of ToolStripMenuItem)

        myMenus.Add(menuItemParent)
        myMenus.Add(New ToolStripMenuItem("New Menu"))

        myMenus.Item(0).Text = "new text here"
        myMenus.Item(1).Text = myMenus.Item(1).Text + " Modified"


     


    You can then loop through the collection:




        For i As Integer = 0 To myMenus.Count - 1

            dynamicMenu.Items.Add(myMenus.Item(i))

        Next


     


    Good luck

  • Creating a menu when my application is executing !!!