How to determine which dynamic menu item was clicked?

D

Dean Slindee

I have built several dynamic menu items, based on entries in a datatable.
On each dynamic menu item, the tag property is loaded with a URL address.
Now I would like to recover the tag value when the user clicks on any of the
dynamic menu items. Since there are no event handlers for the dynamic menu
items, how can I get the tag value?

ds =
GetModuleMenuRowsWithModuleIDCategoryID(My.Application.Info.ProductName.ToString,
cCity)

For Each dr In ds.Tables(0).Rows

Dim innerItem As New
ToolStripMenuItem(String.Format(dr.Item("UrlTitle").ToString))

innerItem.Tag = dr.Item("UrlAddress").ToString

itm.DropDownItems.Add(innerItem)

Next dr



Thanks,

Dean S
 
B

Blake

Dean Slindee said:
I have built several dynamic menu items, based on entries in a datatable.
On each dynamic menu item, the tag property is loaded with a URL address.
Now I would like to recover the tag value when the user clicks on any of
the dynamic menu items. Since there are no event handlers for the dynamic
menu items, how can I get the tag value?

ds =
GetModuleMenuRowsWithModuleIDCategoryID(My.Application.Info.ProductName.ToString,
cCity)

For Each dr In ds.Tables(0).Rows

Dim innerItem As New
ToolStripMenuItem(String.Format(dr.Item("UrlTitle").ToString))

innerItem.Tag = dr.Item("UrlAddress").ToString

itm.DropDownItems.Add(innerItem)

Next dr



Thanks,

Dean S

You need to attach a delegate manually.

AddHandler innerItem.Click , AddressOf MenuClickHandler

And then write your own handler for the click event like so...

Private Sub MenuClickHandler(sender as object, e as eventargs)
' do something.
End Sub

You can use the same handler for all of your dynamic items
 

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

Top