I have a list like this:
List<Controls> list = new List<Controls>
How to handle adding new position to this list?
When I do:
myObject.myList.Add(new Control());
I would like to do something like this in my object:
myList.AddingEvent += HandleAddingEvent
And then in my HandleAddingEvent delegate handling adding position to this list. How should I handle adding new position event? How can I make this event available?
You could inherit from List and add your own handler, something like
Warning
Be aware that you have to re-implement all methods which add objects to your list.
AddRange()will not fire this event, in this implementation.We did not overload the method. We hid the original one. If you
Add()an object while this class is boxed inList<T>, the event will not be fired!