473,804 Members | 3,018 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
DataSourceChang e. Callbacks assigned to ItemCheck and DataSourceChang e
events at designtime.

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

private void controlX_DataSo urceChanged(obj ect sender, System.EventArg s e)

{

this.controlX.I temCheck -= new
ItemCheckEventH andler(this.con trolX_ItemCheck );

try

{

....

}

finally

{

this.controlX.I temCheck += new
ItemCheckEventH andler(this.con trolX_ItemCheck );

}

}

Now, the question is how to do the same thing without explicitly specifying
this.controlX_I temCheck 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).GetT ype().GetEvent( "ItemCheck" );

// Delegate d = Delegate.Create Delegate(ei.Eve ntHandlerType, this,
"controlX_ItemC heck");

ei.RemoveEventH andler(sender, d);

try

{

...

}

finally

{

ei.AddEventHand ler(sender, d);

}

Thanks in advance,
Serge


Jul 21 '05 #1
1 1532
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 .GetInvocationL ist() 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(Delegat e d in myClass.myEvent .GetInvocationL ist())
{
evtList.Add(d);
myControl.myEve nt -= new EventHandler(d) ;
}

// do something here. . .
// now reassign
foreach(Delegat e d in evtList)
{
myControl.myEve nt += 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
1605
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 on the fly from a common php page generator. What functions would i need? Is there a function that would return the string www .
3
5029
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 than prepending them with On as in OnClose and OnClick? The way it is now, I encounter a lot of naming conflicts/ambiguity when trying to follow Microsoft's reccommened approach in naming my own events.
19
4115
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 the code that implements managing unbound controls on forms given the superior performance of unbound controls in a client/server environment. I can easily understand a newbie using bound controls or someone with a tight deadline. I guess I need...
48
3255
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 "huge" Indy is both as a project, in support, development, and use. But Indy is new to the .net world. Indy is a HUGE library implementing over 120 internet protocols and standards and comes with complete source. Its an open source project, but not...
2
4448
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 then skip this file and move onto the next file (line). If file is there then move to a sirectory. Here is the code I have (Feel free to make corrections as needed. If possible make changes in red)
1
333
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 lets say two events: ItemCheck and DataSourceChange. Callbacks assigned to ItemCheck and DataSourceChange
10
3310
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 normal form view. I know they have the option to change that, but I trying to make this as user friendly as possible (and to learn about VBA for myself) So I thought I'd use two option buttons to identify this choice ........one for Forms view,...
4
3255
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 correct syntax for those methods? In MFC, I can simply choose event handlers from a list and they are inserted automatically with the correct signature. Similar deal with Visual Basic 6. But I can't seem to find anything like this in C#.
15
4036
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 be Java or ActiveX. Thank you.
0
9706
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10332
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10321
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7620
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6853
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5522
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3820
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.