VB.Net Sub Menu Array

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to add sub menu options at runtime.

It was a simple task in VB6

For x = 0 to 5
Load mnuNames(x)
mnuNames(x).enabled = true
mnuNames(x).visible = true
mnuNames(x).Caption = strNameToDisplay(x)
Next

Is there a way to perform this function in VB.Net?
Once added how is the event captured?

Any assistance would be greatly appreciated thanks.
 
Hi,
Try this code
Dim objMenuItem As MenuItem
objMenuItem = MenuItem1.MenuItems.Add("New Menu Name")
AddHandler objMenuItem .Click, AddressOf MenuItem3_Click

Private Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)

End Sub
 
Thanks for the suggestion it helped, I can't help but feel that VB.Net is in
need of some improvements a simple task in VB6 has become overwhelming! I
have modified my code too:

Dim mnu As System.Windows.Forms.Menu
Dim mnuMain As MainMenu
Dim newMenuItem As New MenuItem
Dim x, y as integer

mnuMain = MainMenu1
newMenuItem.Text = "View Names"

mnuMain.MenuItems.Add(newMenuItem)

For x = 1 To 5
newMenuItem.MenuItems.Add(strNames(x))
y = mnuMain.MenuItems.count 'Capture index
Next

I still have problems in capturing the events dynamically at runtime.
I would have to hand code each name into an event which defeats the purpose
of the code if this knowledge existed it would be done at design time.

Once again thank you Senthamil, this is just another brick in the wall to
overcome.
 
Back
Top