Using Events inside a collection

gpark

New member
Joined
Dec 18, 2005
Messages
2
Programming Experience
1-3
If I create multiple instances of a class which has an event associated with it and add them to a colletion, how do I know which instance triggered the event?
 
The "sender" argument to the event handler is ALWAYS the object that raised the event. It is of type Object though so you need to cast it as the correct type. If this is an event of your own creation that is a member of the collection itself then you would need to create your own class that inherits EventArgs class and give it a property that refers to the item that raised the event, just like the ToolBar.ButtonClick event handler takes a ToolBarButtonClickEventArgs object that has a Button property that indicates which butoon was clicked.
 
Back
Top