Re: How to reassign event handler at runtime
- From: "Nicholas Paldino [.NET/C# MVP]" <mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 13 Sep 2007 15:09:37 -0400
Gregory,
You will have to hold a reference to the old handler, and then remove
it:
// Store this somewhere.
RetrieveVirtualItemEventHandler oldHandler = ...;
// When adding the event, remove the old handler.
lv.RetrieveVirtualItem -= oldHandler;
// Add the new handler.
lv.RetrieveVirtualItem += this.MyHandler;
--
- Nicholas Paldino [.NET/C# MVP]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx
"Gregory Khra" <GregoryKhra@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:70CBB055-C36A-41E8-AE5C-69B7E9ACFF41@xxxxxxxxxxxxxxxx
My code assigns event handler at runtime:
/*ListView*/ lv.RetrieveVirtualItem += this.MyHandler;
This line can be executed several times with the same list box and
different
handlers (to be exact, the same handler coming from different instances of
an
object). It appears from debugging that each execution adds a handler
instead of overwriting it. As a result event causes the execution of all
old
handlers as well as the new one.
Am I right? If yes, how can I remove the old handlers?
Gregory
.
- Prev by Date: Re: Simple WinForm ( Not Responding ) Refesh Issue C# 2.0
- Next by Date: Error: No overload for method 'ToString' takes '1' arguments
- Previous by thread: User Control Datasource
- Next by thread: Re: How to reassign event handler at runtime
- Index(es):
Relevant Pages
|