addhandler and removehandler - work as advertised?

J

jeff

I have code in a form load (and I tried it in New() too) that says:

"Removehandler me.comboCity.SelectedIndexChanged,
me.comboCity_selectedIndexChanged"

I needed to disable processing of the combo being changed while the control
binds to the arraylist data via standard data binding during form load.

Then after the data loads and the form is done I code:

"AddHandler me.comboCity.SelectedIndexChanged, AddressOf
me.comboCity_selectedIndexChanged"

But the event still fires while the databinding is taking place, why? The
event was supposed to be disabled?

Thanks,

Jeff
 
R

Rajeev Soni

hi
well i dont know how it is done in VB.NET syntax..... in C# i am doing this way...

created the handler object......... EventHandler ehDBCombo = new EventHandler(XYZMethod());

and whenever required...
DBCombo.SelectedIndexChanged -= ehDBCombo;
..
..
.. WRITE UR CODE HERE
..
..
DBCombo.SelectedIndexChanged += ehDBCombo;

rajeev
 
J

Jonny

hi, jeff,
try to rewrite the statment in
RemoveHandler me.comboCity.SelectIndexChanged, addressof
me.combocity_selectedindexchanged
for more information ,you may read the following topic in msdn

ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/vbls7/html/vblrfVBSpec7_3.htm

best regards,

Jonny
 
C

Claes Bergefall

The RemoveHandler call is missing an AddressOf
(compare it to your AddHandler call)

Turn on both Option Explicit and Option Strict and
you should get a compiler error

/claes
 
C

Chris Dunaway

Just out of curiosity, does your comboCity_selectedIndexChanged method have
a Handles clause at the end? If so, you probably need to remove this as it
may be adding an additional handler to your event.

Just a thought.

Chris
 

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