Generic menu event for a menu with dynamic items

  • Thread starter Thread starter Mac via DotNetMonster.com
  • Start date Start date
M

Mac via DotNetMonster.com

Hi all,

I have a menu that is populated from the results of an SQL query. For
example lets say the menu contains a list of clients IDs. I would like to
click on a particular item and open up a form passing in the particular
client ID that I have clicked on.

It is possible to have a generic event that is activated for any item that
is selected in the menu?


regards,

Mac
 
Mac via DotNetMonster.com said:
I have a menu that is populated from the results of an SQL query. For
example lets say the menu contains a list of clients IDs. I would like to
click on a particular item and open up a form passing in the particular
client ID that I have clicked on.

It is possible to have a generic event that is activated for any item that
is selected in the menu?

Extend each meu item with a 'Tag' property:

<URL:http://www.dotnetrix.co.uk/menus.html>
-> "Create an Extender Component to add a Tag property to MenuItems."

Then use 'AddHandler' to add an event handler which is shared between all
menu items. Inside the event handler check the menu item's tag ('sender'
will contain a reference to the menu item).
 
Hi add a mainmenu to a form, add one item to the mainmenu then
copy paste the following code in the form load event and copy paste the
Private Sub MenuItem_Click somewhere outside the form load event, and test
the app.


Dim x As MenuItem
For i As Integer = 0 To 9
x = New MenuItem
x.Text = CStr(i)
AddHandler x.Click, AddressOf MenuItem_Click
MainMenu1.MenuItems(0).MenuItems.Add(x)
Next


Private Sub MenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
MsgBox(DirectCast(sender, MenuItem).Text)
End Sub


hth Greetz Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top