From: Anil Gupte/iCinema.com on
How do I add items to a menu while simultanesously adding an OnClick event
for each. I have an 2Xn array of text items (labels) and matching URLs.e.g.

"Google", www.google.com
"Yahoo", www.yahoo.com

I want the first column to be the menu label and the second column is where
the browser goes when the menu is clicked. OK, so the first part is easy.

AdditionalToolStripMenu.DropDownItems.Add(strResearchLinksArray(i, 1))

How do I go to strResearchLinksArray(i, 0) when that item is clicked. I am
vb.net 2005.
--
Thanx & Regards,
Anil Gupte


From: Armin Zingler on
Am 02.03.2010 17:38, schrieb Anil Gupte/iCinema.com:
> How do I add items to a menu while simultanesously adding an OnClick event
> for each. I have an 2Xn array of text items (labels) and matching URLs.e.g.
>
> "Google", www.google.com
> "Yahoo", www.yahoo.com
>
> I want the first column to be the menu label and the second column is where
> the browser goes when the menu is clicked. OK, so the first part is easy.
>
> AdditionalToolStripMenu.DropDownItems.Add(strResearchLinksArray(i, 1))
>
> How do I go to strResearchLinksArray(i, 0) when that item is clicked. I am
> vb.net 2005.

dim item = AdditionalToolStripMenu.DropDownItems.Add(strResearchLinksArray(i, 1))
item.tag = i

In the click event:

Dim index = DirectCast(DirectCast(sender, ToolStripItem).Tag, Integer)
dim address = strResearchLinksArray(index, 0)


- or -

Create a class inheriting from ToolStripMenuItem and add a property "ServerName".



--
Armin
From: Anil Gupte/iCinema.com on

Sorry, I have been unable to connect for a while. Thanx for your help.

I am not sure I understand your solution. You said "in the click event"
and you have me add a line. My question is, how does one add or assign a
click event to each item in the array?

--
Thanx & Regards,
Anil Gupte
"Armin Zingler" <az.nospam(a)freenet.de> wrote in message
news:%235pL30iuKHA.4908(a)TK2MSFTNGP06.phx.gbl...
> Am 02.03.2010 17:38, schrieb Anil Gupte/iCinema.com:
>> How do I add items to a menu while simultanesously adding an OnClick
>> event
>> for each. I have an 2Xn array of text items (labels) and matching
>> URLs.e.g.
>>
>> "Google", www.google.com
>> "Yahoo", www.yahoo.com
>>
>> I want the first column to be the menu label and the second column is
>> where
>> the browser goes when the menu is clicked. OK, so the first part is
>> easy.
>>
>> AdditionalToolStripMenu.DropDownItems.Add(strResearchLinksArray(i, 1))
>>
>> How do I go to strResearchLinksArray(i, 0) when that item is clicked. I
>> am
>> vb.net 2005.
>
> dim item =
> AdditionalToolStripMenu.DropDownItems.Add(strResearchLinksArray(i, 1))
> item.tag = i
>
> In the click event:
>
> Dim index = DirectCast(DirectCast(sender, ToolStripItem).Tag, Integer)
> dim address = strResearchLinksArray(index, 0)
>
>
> - or -
>
> Create a class inheriting from ToolStripMenuItem and add a property
> "ServerName".
>
>
>
> --
> Armin


From: Armin Zingler on


Am 07.03.2010 01:02, schrieb Anil Gupte/iCinema.com:
> Sorry, I have been unable to connect for a while. Thanx for your help.
>
> I am not sure I understand your solution. You said "in the click event"
> and you have me add a line. My question is, how does one add or assign a
> click event to each item in the array?

Sorry, only the last question ("How do I go to strResearchLinksArray...")
stayed in my mind. :-) Because you said...

>> OK, so the first part is
>> easy.
>>
>> AdditionalToolStripMenu.DropDownItems.Add(strResearchLinksArray(i, 1))

....I assumed that adding the items already works. To have a procedure handle
an event, use the Addhandler statement:

> dim item =
> AdditionalToolStripMenu.DropDownItems.Add(strResearchLinksArray(i, 1))

AddHandler item.Click, AddressOf OnMenuItemClick

'...

Sub OnMenuItemClick(ByVal sender As Object, ByVal e As System.EventArgs)
'code from last post
End Sub



--
Armin