Microsoft intrdouced a new collection class, in .Net which give you notifications(events), while items getting added, removed and refreshed. You can get more information about this class in this link ObservableCollection Generic Class. As per the MSDN documentation this class is available in System.Collections.ObjectModel,but I am unable to find this class in VS 2005 in .Net 2.0. So I created a class, to give me almost same functionality
Public Class ObserverCollection(Of T)
Inherits System.Collections.Generic.List(Of T)
Public Event ItemAdded(ByVal o As T)
Public Event ItemRemoved()
Public Overloads Sub Add(ByVal Value As T)
MyBase.Add(Value)
RaiseEvent ItemAdded(Value)
End Sub
Public Overloads Sub Remove(ByVal Value As T)
MyBase.Remove(Value)
RaiseEvent ItemRemoved()
End Sub
End Class
It is a simple implementation, where I am using the System.Collections.Generic.List(Of T) as my base class, and I am overloading the methods. In the overloaded methods, I am raising the events.
Update : This class not available on .Net Framework 2.0
Update 2: This class will available on Visual Studio 2008, only after adding reference to the WindowBase.dll, normally it will not come. You need to add reference explicitly
ObservableCollection is new to .NET 3.0. It is not available in 2.0. Actually at the end of the MSDN documentation page it says “Supported in: 3.0″
Thanks Jonas