cancel event

  • Thread starter Thread starter Shawn
  • Start date Start date
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
 
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
 
.... 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
 
Back
Top