Results 1 to 3 of 3

Thread: [RESOLVED] List of all Options from ToolStripMenuItem

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2010
    Posts
    254

    Resolved [RESOLVED] List of all Options from ToolStripMenuItem

    Hi everyone,

    I have a mainmenu form with ToolStripMenuItem, I am creating user rights form, for this i need list of all options so that i can save in table and use it with login user.

    I used this code, this code shows only name of Top level menu, how can i get list of all children for that parent option.
    Please help me out .

    Code:
    For A1 = 0 To MenuStrip.Items.Count - 1
         MsgBox(MenuStrip.Items(A1).Name)
    Next A1
    Thanks
    Ladak

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,461

    Re: List of all Options from ToolStripMenuItem

    A menu is inherently a recursive structure, so you would generally use recursion to navigate it.

    https://www.google.com.au/search?q=v...L83n8AX4oYCABg

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2010
    Posts
    254

    Re: List of all Options from ToolStripMenuItem

    Thanks for your reply, Just after posting this thread I found the solution... here is the code

    Code:
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            Dim menues As New List(Of ToolStripItem)
            For Each t As ToolStripItem In MenuStrip.Items
                GetMenues(t, menues)
            Next
    
            Dim msg As String = ""
            For Each t As ToolStripItem In menues
                msg &= t.Name & vbCrLf
            Next
            MessageBox.Show(msg)
        End Sub
        Public Sub GetMenues(ByVal Current As ToolStripItem, ByRef menues As List(Of ToolStripItem))
            menues.Add(Current)
            If TypeOf (Current) Is ToolStripMenuItem Then
                For Each menu As ToolStripItem In DirectCast(Current, ToolStripMenuItem).DropDownItems
                    GetMenues(menu, menues)
                Next
            End If
        End Sub
    Thanks again.
    Ladak

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width