473,699 Members | 2,570 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

need help with EventHandler

hi,
i wrote my own generic class based on IList that fires events, so it's just
a better List<class.
When my "EventedLis t" fires an event I don't want to take "this" as sender
instead i would like to use the instance of the class that's holding my EventedList
object that currently fires.
Any ideas how to get this to work?

thanks
Sascha
Aug 9 '06 #1
4 1217
Well, either A: the list would need to know what sender to use, e.g. ctors:

private readonly object _sender;
public EventedList() : this(this) {}
public EventedList(obj ect sender) {
_sender = sender;
}

(and then use _sender as the sender), or B: you would need to catch the
event at the holder and forward with the revised sender, i.e.

_eventedList = new EventedList();
_eventedList.So meEvent += OnSomeEvent;
....
public event EventHandler SomeEvent;
protected void OnSomeEvent(obj ect sender, EventArgs args) {
EventHandler handler = SomeEvent;
if(handler!=nul l) handler(this, args); // ignore sender
}

===

A involves less hops, but limits you to one master holder per list - which
may not be unreasonable. As an aside, with A you could expose the event
(without incurring a hop) on the holder via (using similar to the above
example):

_eventedList = new EventedList();
public event EventHandler SomeEvent {
add {_eventedList.S omeEvent += value;}
remove {eventedList.So meEvent -= value;}
}

Marc
Aug 9 '06 #2
thanks for you suggestions marc, but I'm wondering if there's no way through
reflection or any mechanism like this?

Sascha
Well, either A: the list would need to know what sender to use, e.g.
ctors:

private readonly object _sender;
public EventedList() : this(this) {}
public EventedList(obj ect sender) {
_sender = sender;
}
(and then use _sender as the sender), or B: you would need to catch
the event at the holder and forward with the revised sender, i.e.

_eventedList = new EventedList();
_eventedList.So meEvent += OnSomeEvent;
...
public event EventHandler SomeEvent;
protected void OnSomeEvent(obj ect sender, EventArgs args) {
EventHandler handler = SomeEvent;
if(handler!=nul l) handler(this, args); // ignore sender
}
===

A involves less hops, but limits you to one master holder per list -
which may not be unreasonable. As an aside, with A you could expose
the event (without incurring a hop) on the holder via (using similar
to the above example):

_eventedList = new EventedList();
public event EventHandler SomeEvent {
add {_eventedList.S omeEvent += value;}
remove {eventedList.So meEvent -= value;}
}
Marc

Aug 9 '06 #3
if there's no way through reflection or any mechanism like this?
What? for the list to know who it's "owner" is? No, firstly because
reflection doesn't offer (AFAIK) backtrace capability (i.e. "who can see
me?"), but mainly because "owner" here is an invention; in the pure sense,
any number of objects could hold a reference to the list; which is the
owner? none specifically. It is only because you are holding this e.g. as a
private member on a class that this concept holds water, hence you would
need to tell it e.g. in the ctor (or event forwarding / spoofing).

Have I answered the correct question? I wasn't quite sure...

Marc
Aug 9 '06 #4
hi Marc,

thanks that's exactly what i wanted to know

Sascha
>if there's no way through reflection or any mechanism like this?
What? for the list to know who it's "owner" is? No, firstly because
reflection doesn't offer (AFAIK) backtrace capability (i.e. "who can
see me?"), but mainly because "owner" here is an invention; in the
pure sense, any number of objects could hold a reference to the list;
which is the owner? none specifically. It is only because you are
holding this e.g. as a private member on a class that this concept
holds water, hence you would need to tell it e.g. in the ctor (or
event forwarding / spoofing).

Have I answered the correct question? I wasn't quite sure...

Marc

Aug 9 '06 #5

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

Similar topics

5
4307
by: RickDee | last post by:
Please help, anybody. I am trying to write a program so that it can launch an exe file ( which is also genereated in C# ) and then simulate the button clicking and invoke the methods inside the exe. The button clicking part is working fine, but I just cannot get the method call. Here is my program snippet. **************************************************************
12
4415
by: aplaxas | last post by:
Hi! "CDemo.Call" eventHandler is added to "button3.click" Event when both button1 and button2 are clicked. However, I want to add "cd.Call" only one time even though I clicked both button1 and button2. For Example, 1. Click button1 2. Click button2
5
2388
by: MFC | last post by:
Ok, after three C# books, (C# How to Program, Programming in the Key of C#, and C# Weekend Crash Course) and three weeks, I believe I have tried everything to make a certain form function correctly. I am trying to learn C# after playing around for a bit with procedural programming with PHP, not OOP, and believe I have learned quite a bit in three weeks, just not enough to accomplish this one task. If anyone has a bit of free time and...
17
2673
by: Hazz | last post by:
In this sample code of ownerdraw drawmode, why does the '(ComboBox) sender' line of code need to be there in this event handler? Isn't cboFont passed via the managed heap, not the stack, into this cboFont_DrawItem event handler? Why does it need to be cast? -hazz ,................. cboFont.Items.AddRange(FontFamily.Families); } private void cboFont_DrawItem(object sender,
5
1438
by: Raj Chudasama | last post by:
I have a client server app. On the client i have buttons (derived from user contol) that let user perform actions when they are connected to the server. so when they connect (using a menuitem) i add event handlers to the buttons and when they disconnect i remove them. Now, everything works fine when they connnect for the first time. All of the msgs are sent propoerly by the client. To figure out what button is click by the client i used...
0
1661
by: RSB | last post by:
Hi Every one, i am trying to create a UserControl and i am passing a Array of strings to it. Now based on the Array elements i am creating the LinkButtons Dynamically. I am also passing a Event to this control and Lining the OnClick event of these LinkButtons to this Event. (Which works fine). Now the Thing which i cannot achieve is i want to Change the Back Color of the Clicked to LinkButton To a different color and i also don't want to...
0
1552
by: Diffident | last post by:
Hello All, I have an asp:button and I have tied an eventhandler to this button's click event which means that the eventhandler should be executed everytime I click the button. But to my frustration, the eventhandler does not get executed everytime I click the button. I have to click the button twice at times to make sure that the event handler is being called. Why is the control behaving in this way? This problem is not specific for a...
1
2011
by: mostafahamdyfcis | last post by:
Hello all I have used the sample code which exist in the following URL: http://www.eggheadcafe.com/articles/javascript_modal_dialog.asp which create modal dialog box, but some problem appears with FF browser which is when I click the show Modal #1 link another modal dialog box appears to me, I set the interval of setinterval function to 50 instead 5 and it works very good and the problem whcih appears with FF never appears with IE,...
4
2353
by: Ty | last post by:
Hello all, I am creating a website in VS 2008 VB.net. On one of my pages I am using the Table control to make a type of calendar a IN/OUT board. The problem I found after I wrote all the code to create the table was that there is not Cell Click event. So I did some looking and asked around and got this C# (see below) version of a class that someone built to create a clickable cell.
0
8689
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
8618
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9035
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
8916
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,...
0
8885
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3058
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
2348
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2010
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.