Raise event when a list has new item?
c#, events, list
Solution
Have a look at `BindingList<T>` and `ObservableCollection<T>`. This answer explains the difference between the two.
Apart from binding, you can subscribe to the change events like so:
`BindingList<T>.ListChanged`:
items.ListChanged += (sender, e) => {
// handle the change notification
};
`ObservableCollection<T>.CollectionChanged`:
items.CollectionChanged += (sender, e) => {
// handle the change notification
};
Problem
I write a control that displays a list of items (in this case just strings). I gave the developer a list of items where he can add and remove items (see code below). I wished there would be a way to be notified when a new item has been added and stuff. So as a reaction the control can update. ``` private List<string> items = new List<string>(); public List<string> Items { get { return items; } } ``` How can I do that ? `List<...>` has no events. What can I do ?