cancel event

S

Shawn

Hi.
I'm having trouble with my ListBox. This is what I want to do. I have two
listboxes. When I click on an item in the first one I want the second one
to fill up with values depending on which item was clicked in the first
listbox. The problem is that ListBox1_SelectedIndexChanged fires when I set
the listbox's datasource. Is there anyway to prevent this? Can I "turn
off" the event and turn it back on when I need it?

Thanks,
Shawn
 
C

Chuck Rudolph

Shawn, In c#

On is :
this.listBox1.SelectedIndexChanged += new
System.EventHandler(this.listBox1_SelectedIndexChanged);

And off would be:
this.listBox1.SelectedIndexChanged -= new
System.EventHandler(this.listBox1_SelectedIndexChanged);


....Chuck
 
B

Beth Massi [Architect MVP]

.... and if you're using VB.NET:

Instead of using the Handles clause, use AddHandler/RemoveHandler:

Start handling the event:
AddHandler ListBox1.SelectedIndexChanged, AddressOf
ListBox1_SelectedIndexChanged

Stop handling the event:
RemoveHandler ListBox1.SelectedIndexChanged, AddressOf
ListBox1_SelectedIndexChanged
 

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