Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I made winform by vb.net and put Mainmenu control in form.

One thing that I want to achieve is to get each sub name by loop from Mainmenu control

For example)
Parent Menu-fruit(textname) f1(name)
Child Menu-banana(textname) b1 (name)
Child Menu-melon(textname) m1 (name)
Child Menu-apple(textname) a1 (name)

I want to get b1, m1, a1 but I don't know how to make it by vb.net

Could you help me to use this code as below?

VB
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    Me.SetMenuItemStates(Me.MainMenu1.MenuItems)
End Sub

Private Sub SetMenuItemStates(ByVal items As MenuItem.MenuItemCollection)
    Dim fruit_name As String

    For Each item As MainMenu In items

        fruit_name = item.Name

    Next item
End Sub

End Class
Posted
Updated 24-Aug-15 19:04pm
v6
Comments
Patrice T 24-Aug-15 6:00am    
This code can't work at all, nowhere.
Member 11410248 24-Aug-15 8:37am    
Can you help me to correct this code?
Andy Lanng 24-Aug-15 6:21am    
ppolymorphe is correct. Your code appears to be missing some lines.
Member 11410248 24-Aug-15 8:36am    
Can you help me to correct this code?
Andy Lanng 24-Aug-15 8:41am    
You have an End If within the For Each. End If can only appear after an If clause.

menu01 changes on each loop and does nothing within the loop. perhaps this was part of the If clause?

Me.Controls refers to the controls on the form / page. This will not show you the menu items.

post the code / markup for the mainmenu control. It'll be easier to help you if we know what your manu is

1 solution

There is no solution to find

Your code is probably doing what you want, which is I want to get b1, m1, a1, but since you simply do nothing and discard what you got, you don't see anything.

Advice: try to do something with what you get.
Decide what you want to do with what you get.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900