473,395 Members | 1,623 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

I need to clear temporary the event sinks from another event and then restore them, but I don't know which methods signed up for that event

Hi,
I have a situation where I need to clear the event sinks from an event. But
let's say I don't know which methods (by name, I mean) signed up for that
event.
I do have a control with lets say two events: ItemCheck and
DataSourceChange. Callbacks assigned to ItemCheck and DataSourceChange
events at designtime.

The logic within DataSourceChanged callback requires temporary to disable
the ItemCheck which can be accomplished by smth. Like this:

private void controlX_DataSourceChanged(object sender, System.EventArgs e)

{

this.controlX.ItemCheck -= new
ItemCheckEventHandler(this.controlX_ItemCheck);

try

{

....

}

finally

{

this.controlX.ItemCheck += new
ItemCheckEventHandler(this.controlX_ItemCheck);

}

}

Now, the question is how to do the same thing without explicitly specifying
this.controlX_ItemCheck name? I'm looking for something like I was able to
do in Delphi, for example,

1) store the existing one to the local variable

2) assign this one to null

3) do some work here...

4) restore back to the one stored into local variable

I believe you know what I'm talking about.

I know I have to use reflection in .NET/C# in order to get this thing done,
but how?

P.S. Such things does not help because I have to specify the name of the
callback explicitly as well:

// EventInfo ei = (sender as MyControl).GetType().GetEvent("ItemCheck");

// Delegate d = Delegate.CreateDelegate(ei.EventHandlerType, this,
"controlX_ItemCheck");

ei.RemoveEventHandler(sender, d);

try

{

...

}

finally

{

ei.AddEventHandler(sender, d);

}

Thanks in advance,
Serge


Jul 21 '05 #1
1 1493
Because an event is not a delegate. An event is member of a type, like
a property or a method. A delegate is a type, like String or Int32.

When you try myClass.myEvent.GetInvocationList() you are trying to treat
an event as a delegate.
joe mamma wrote:
did you ever get an answer to this???

I was trying something along the lines of this, but it doesn't work. If
somewone can tell me why it doesnt work, I might be able to figure out how it
should work.

ArrayList evtList = new ArrayList();

foreach(Delegate d in myClass.myEvent.GetInvocationList())
{
evtList.Add(d);
myControl.myEvent -= new EventHandler(d);
}

// do something here. . .
// now reassign
foreach(Delegate d in evtList)
{
myControl.myEvent += new EventHandler(d)
}

Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: wandaring | last post by:
here's my problem If a visitor comes to visit my site and puts in his / her browser www . mysite.com/Ceciliasfirstpage.html (excluding the space) I want Ceciliasfirstpage.html to be generated...
3
by: boxboy | last post by:
I am hoping someone from Microsoft could shed some insight into this question. Why did microsoft decide to use a verb based naming convtion for events rather such as Close and Click for rather...
19
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate...
48
by: Chad Z. Hower aka Kudzu | last post by:
A few of you may recognize me from the recent posts I have made about Indy <http://www.indyproject.org/indy.html> Those of you coming to .net from the Delphi world know truly how unique and...
2
by: Keith Kowalski | last post by:
I anm opening up a text file reading the lines of the file that refer to a tif image in that file, If the tif image does not exist I need it to send an email stating that the file doesn't exist...
1
by: Serge Shimanovsky | last post by:
Hi, I have a situation where I need to clear the event sinks from an event. But let's say I don't know which methods (by name, I mean) signed up for that event. I do have a control with...
10
by: jerry.ranch | last post by:
I have a series of comboboxes on a form that are used to display forms in DS view (theres a qry behind it all). This is working well for me. Some people like to see the data in DS view, some in...
4
by: Jonathan Wood | last post by:
I'm building a Web application but this question should be common to all C# applications. When I use a class, and I want to add event handlers or override base class methods, how do I know the...
15
by: javelin | last post by:
I need to be able to create a javascript based drawing/signature box, and be able to save it. Can someone refer me to a script that will allow this, or even a 3rd party package for sale? It can't...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.