How to determine which dynamic menu item was clicked?

  • Thread starter Thread starter Dean Slindee
  • Start date Start date
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
 
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
 
Back
Top