any way to find what triggered an event?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a listbox and auto generated lb_SelectedIndexChanged event that
handles lb.SelectedIndexChanged.

The event obviously fires when I change the selectedIndex visually with a
mouse and also when I do lb.selectedindex=1 (any different value from what it
was before) in various different subroutines?

Is there any way to know where the event was triggered from? Which
subroutine called it? could I use reflection to get that info?

Any tips?

Thank you
 
I have a listbox and auto generated lb_SelectedIndexChanged event that
handles lb.SelectedIndexChanged.

The event obviously fires when I change the selectedIndex visually with a
mouse and also when I do lb.selectedindex=1 (any different value from what it
was before) in various different subroutines?

Is there any way to know where the event was triggered from? Which
subroutine called it? could I use reflection to get that info?

I don't know if there's an "easy" way. I guess I would ask, why do you
need to know?

If there's just one spot where you may set an intial value and don't
want the event to fire when setting it, you could detach the event
handler, set your value and then reattach the event handler:

listbox1.SelectedIndexChanged -= new EventHandler
(lb_SelectedIndexChanged);
listbox1.SelectedIndex = 2;
listbox1.SelectedIndexChanged += new EventHandler
(lb_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

Back
Top