473,388 Members | 1,207 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

AddHandler question.

EMW
I use the following code in the POPUP event of a contextmenu:

mnuItem = New MenuItem
mnuItem.Text = "Shelter"
cmThs.MenuItems.Add(mnuItem)
AddHandler mnuItem.Click, AddressOf MenuItemClicked
mnuItem = New MenuItem
mnuItem.Text = "Building"
cmThs.MenuItems.Add(mnuItem)
AddHandler mnuItem.Click, AddressOf MenuItemClicked
mnuItem = New MenuItem
mnuItem.Text = "Bsc"
cmThs.MenuItems.Add(mnuItem)
AddHandler mnuItem.Click, AddressOf MenuItemClicked
MenuItemClicked is a function in the same form.

It works fine, but I'm having strange problems I''m wandering if this is
the
reason of it.
Simulair code is used for each textbox where the contextmenu is activated.

Now how do I remove all the handlers that were created.
I want to do this in the MenuItemClicked, because after that the handler is
not needed anymore untill the user activates the contextmenu again.
Is there some of way of removing all EventHandlers pointing to a specific
procedure?

rg,
Eric


Nov 22 '05 #1
2 1568
Eric,

MenuItem is a part of the MenuItemCollection, in my opinion it should be
therefore very easy to do with a (see this as pseudo not tested and typed
here) to do what I thought that you where asking.

for each MnIt as MenuItem in cmThs.MenuItems
RemoveHandler MnIt.Click, AddressOf MenuItemClicked
next

I hope that this helps?

Cor

"EMW" <so*****@MikroZoft.com>
I use the following code in the POPUP event of a contextmenu:

mnuItem = New MenuItem
mnuItem.Text = "Shelter"
cmThs.MenuItems.Add(mnuItem)
AddHandler mnuItem.Click, AddressOf MenuItemClicked
mnuItem = New MenuItem
mnuItem.Text = "Building"
cmThs.MenuItems.Add(mnuItem)
AddHandler mnuItem.Click, AddressOf MenuItemClicked
mnuItem = New MenuItem
mnuItem.Text = "Bsc"
cmThs.MenuItems.Add(mnuItem)
AddHandler mnuItem.Click, AddressOf MenuItemClicked
MenuItemClicked is a function in the same form.

It works fine, but I'm having strange problems I''m wandering if this is
the
reason of it.
Simulair code is used for each textbox where the contextmenu is activated.

Now how do I remove all the handlers that were created.
I want to do this in the MenuItemClicked, because after that the handler
is
not needed anymore untill the user activates the contextmenu again.
Is there some of way of removing all EventHandlers pointing to a specific
procedure?

rg,
Eric

Nov 22 '05 #2
EMW
Hi Cor,

I also managed to solve this.
I used an array of menuitems to store each created menuitem and then in the
MenuItemClicked routine I called RemoveHandler on each arrayItem.

rg.
Eric
"Cor Ligthert" <no************@planet.nl> schreef in bericht
news:OI**************@TK2MSFTNGP12.phx.gbl...
Eric,

MenuItem is a part of the MenuItemCollection, in my opinion it should be
therefore very easy to do with a (see this as pseudo not tested and typed
here) to do what I thought that you where asking.

for each MnIt as MenuItem in cmThs.MenuItems
RemoveHandler MnIt.Click, AddressOf MenuItemClicked
next

I hope that this helps?

Cor

"EMW" <so*****@MikroZoft.com>
I use the following code in the POPUP event of a contextmenu:

mnuItem = New MenuItem
mnuItem.Text = "Shelter"
cmThs.MenuItems.Add(mnuItem)
AddHandler mnuItem.Click, AddressOf MenuItemClicked
mnuItem = New MenuItem
mnuItem.Text = "Building"
cmThs.MenuItems.Add(mnuItem)
AddHandler mnuItem.Click, AddressOf MenuItemClicked
mnuItem = New MenuItem
mnuItem.Text = "Bsc"
cmThs.MenuItems.Add(mnuItem)
AddHandler mnuItem.Click, AddressOf MenuItemClicked
MenuItemClicked is a function in the same form.

It works fine, but I'm having strange problems I''m wandering if this is
the
reason of it.
Simulair code is used for each textbox where the contextmenu is
activated.

Now how do I remove all the handlers that were created.
I want to do this in the MenuItemClicked, because after that the handler
is
not needed anymore untill the user activates the contextmenu again.
Is there some of way of removing all EventHandlers pointing to a specific
procedure?

rg,
Eric


Nov 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: EMW | last post by:
I use the following code in the POPUP event of a contextmenu: mnuItem = New MenuItem mnuItem.Text = "Shelter" cmThs.MenuItems.Add(mnuItem) AddHandler mnuItem.Click, AddressOf MenuItemClicked...
3
by: Jeffrey A. Voigt | last post by:
Can someone take a quick glace at my code and tell me why my AutoPostBackHandler function does not get fired off at all? What I'm trying to do is get all of the Buttons and DropDownList controls...
4
by: DJ | last post by:
Good morning, Still new at this so please bear with me. I am creating a table dynamically using webcontrols based on the output of a sproc from my database.The table represents test instances...
2
by: Just Me | last post by:
When a document is to be printed I call a method that contains an AddHandler statement. I just realized that if a second copy is to be printed the method is called and the AddHandler is executed...
1
by: EMW | last post by:
I use the following code in the POPUP event of a contextmenu: mnuItem = New MenuItem mnuItem.Text = "Shelter" cmThs.MenuItems.Add(mnuItem) AddHandler mnuItem.Click, AddressOf MenuItemClicked...
3
by: hartley_aaron | last post by:
Hi, I was trying to store the address of the my current handler for a particular event so as to simplify using AddHandler and RemoveHandler throughout my code. However, I cannot seem to get any...
12
by: Tom | last post by:
I use dynamically created controls all the time. I.E. I create the control in code then use AddHandler to add the necessary delegates for processing (like Click, etc). Does one have to call...
15
by: Nathan Sokalski | last post by:
I have a section of my code that dynamically creates LinkButtons to allow the user to go to the page containing a question they have not answered. The code that creates the LinkButton is called, as...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.