Select MenuItem Question

  • Thread starter Thread starter mCompany
  • Start date Start date
M

mCompany

I'm building menus in code from a database. How do I
determine which menu item was selected? Does the
System.EventArgs contain this? If so, what property?

Here's the declaration:

Private Sub Menu_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Click


Thanks!
 
mCompany said:
I'm building menus in code from a database. How do I
determine which menu item was selected? Does the
System.EventArgs contain this? If so, what property?

Here's the declaration:

Private Sub Menu_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Click

How is the menu constructed? What is the base class here?
Typically, the click event comes from the MenuItem, not the
Menu, in which case the sender object is the MenuItem.
 
Hello,

mCompany said:
I'm building menus in code from a database. How do I
determine which menu item was selected? Does the
System.EventArgs contain this? If so, what property?

Here's the declaration:

Private Sub Menu_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Click

Where do you add the code?

Do you add handlers by using AddHandler? You will get a reference to the
MenuItem in the sender parameter.

HTH,
Herfried K. Wagner
 
Hello,

mCompany said:
I am using AddHandler:

AddHandler menuItem.Click, AddressOf Me.MenuItem1_Click

However, what is the syntax for determining which menu
item as selected? Which EventArgs are used to determine
the actual item that was clicked?

Try this:

\\\
MsgBox(DirectCast(sender, MenuItem).Text)
///

HTH,
Herfried K. Wagner
 
Back
Top