SelectedValueChanged event fires too many times

K

Keith-Earl

I have a simple combo box on a VB.NET 1.0 Windows form. The
SelectedValueChanged event fires constantly during form load and whenever
the tab that houses the cbo is reselected. I have tried the usual tricks:
set a form var while the form is loading and ignore the event until the form
is loaded. I still get the event when the user clicks from this tab to
another and back again and since I no longer get a form load I cannot
prevent the SelectedValueChange from firing.

How can I get a true SelectedValueChanged *only* when the user selects a
different value on the list?

thanks, Keith
 
C

Cor Ligthert

Keith,

Are you sure that you are not changing the value inside that event?

Cor
 
K

Keith-Earl

absolutely sure.

I think the event is firing as the cbo is being built. Not sure why
clicking from tab to tab fires it. I am running 1.0, not 1.1 because of a
customer constraint.

Thanks,

Keith
 
C

Cor Ligthert

Keith,

The most simple to avoid this is to Remove the handler and Add it manually
on the place you want it.

AddHandler cbo.SelecteValueChange, AddressOf MySelectedValueChange
RemoveHandler cbo.SelecteValueChange, AddressOf MySelectedValueChange

(And than of course as well in the sub itself as set by the designer)

I hope this helps

Cor
 
K

Keith-Earl

Wow, neat approach. Will try it. My biggest challenge will be knowing
*when* to enable and disable. It's a good idea. Thanks!

Keith
 
B

Brian Swanson

Are you sure you aren't updating the values on the tabs as they are
switching? Changing the .Text value when the tab with the cbo is
selected will cause the event to fire as well.
 

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