D
Dave Coate
Hi
With the following code, I can create a MenuStrip with one item, "Admins".
When the user clicks on Admins, it dynamically adds items to the menu
Admins. (In this case "Dave" And "Elizabeth")
When I run this form, the first time I click on "Admins", nothing happens.
Everytime I click on Admins after that I get the expected behavior.
Can someone tell me what I can do so that the menu item works properly the
first time?
Thanks
Dave Coate
Code:
Private MainMenu As MenuStrip
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
MainMenu = New MenuStrip
'Add menu items to the Main Menu Strip
'The event handlers will populate each menu when the top level
'menu item is clicked
Me.MainMenu.Items.Add("Admins", Nothing, _
New System.EventHandler(AddressOf AdminsMenu_OnClick))
'Add the main menu to the controls collection of the form
Me.Controls.Add(MainMenu)
End Sub
Private Sub AdminsMenu_OnClick(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim cms As New ContextMenuStrip()
Dim Admins() As String = {"Dave", "Elizabeth"}
For Each Admin As String In Admins
cms.Items.Add(Admin, Nothing, _
New System.EventHandler(AddressOf
SelectedAdminMenu_OnClick))
Next
Dim tsi As ToolStripMenuItem = CType(sender, ToolStripMenuItem)
tsi.DropDown = cms
End Sub
Private Sub SelectedAdminMenu_OnClick(ByVal sender As Object, ByVal e As
System.EventArgs)
End Sub
With the following code, I can create a MenuStrip with one item, "Admins".
When the user clicks on Admins, it dynamically adds items to the menu
Admins. (In this case "Dave" And "Elizabeth")
When I run this form, the first time I click on "Admins", nothing happens.
Everytime I click on Admins after that I get the expected behavior.
Can someone tell me what I can do so that the menu item works properly the
first time?
Thanks
Dave Coate
Code:
Private MainMenu As MenuStrip
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
MainMenu = New MenuStrip
'Add menu items to the Main Menu Strip
'The event handlers will populate each menu when the top level
'menu item is clicked
Me.MainMenu.Items.Add("Admins", Nothing, _
New System.EventHandler(AddressOf AdminsMenu_OnClick))
'Add the main menu to the controls collection of the form
Me.Controls.Add(MainMenu)
End Sub
Private Sub AdminsMenu_OnClick(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim cms As New ContextMenuStrip()
Dim Admins() As String = {"Dave", "Elizabeth"}
For Each Admin As String In Admins
cms.Items.Add(Admin, Nothing, _
New System.EventHandler(AddressOf
SelectedAdminMenu_OnClick))
Next
Dim tsi As ToolStripMenuItem = CType(sender, ToolStripMenuItem)
tsi.DropDown = cms
End Sub
Private Sub SelectedAdminMenu_OnClick(ByVal sender As Object, ByVal e As
System.EventArgs)
End Sub