Remove Handler.. & Add Handler...

V

VJ

Here is snippet of my problem

IF Condition1 then
RemoveHandler lblCntrl.Click, AddressOf lbl_ShowItem
AddHandler lblCntrl.Click, AddressOf lbl_ShowMaker2
elseif Condition2 then
AddHandler lblCntrl.Click, AddressOf lbl_ShowItem
RemoveHandler lblCntrl.Click, AddressOf lbl_ShowMaker2
end if

After the above block is executed I try to click on the label.. I have both
the "lbl_ShowItem" and "lbl_ShowMaker2" methods executed. I had to go
include the same IF check inside each method to prevent... Why is the Remove
Handler not removing the old method and adding a new one for the same click
event. Anybody have ideas??

Thanks
VJ
 
O

One Handed Man \( OHM#\)

It doesent remove the method, it simply attaches/removes the method to the
event.

Regards - OHM
 
O

One Handed Man \( OHM#\)

I tried this out, both Labels have their clicks serviced until button one is
pressed, then only label2 works.
\\
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Label1.Click

MessageBox.Show("Label1.Clicked")

End Sub

Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Label2.Click

MessageBox.Show("Label2.Clicked")

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

RemoveHandler Label1.Click, AddressOf Label1_Click

End Sub
//
Regards - OHM
 
H

Herfried K. Wagner [MVP]

* "VJ said:
Here is snippet of my problem

IF Condition1 then
RemoveHandler lblCntrl.Click, AddressOf lbl_ShowItem
AddHandler lblCntrl.Click, AddressOf lbl_ShowMaker2
elseif Condition2 then
AddHandler lblCntrl.Click, AddressOf lbl_ShowItem
RemoveHandler lblCntrl.Click, AddressOf lbl_ShowMaker2
end if

After the above block is executed I try to click on the label.. I have both
the "lbl_ShowItem" and "lbl_ShowMaker2" methods executed. I had to go
include the same IF check inside each method to prevent... Why is the Remove
Handler not removing the old method and adding a new one for the same click
event.

What's 'Condition1' and 'Condition2'? Your code should work.
 
V

VJ

Its just a whether a menu is checked or not... that is it.. The code does
not work.. I tried possibilities I know.. but it keeps the click event..

VJ
 
V

VJ

What happens if I do this?.. is there 2 refrences in memory?

AddHandler lblCntrl.Click, AddressOf lbl_ShowItem
AddHandler lblCntrl.Click, AddressOf lbl_ShowItem

Thanks
VJ
 

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