This sample demonstrates the implementation of the IBindingList for an array list that is used internally, and it also shows how to bind this list to a Grid Grouping control.
Features:
Implementing the IBindingList requires utilization of all members of IBindingList, IList, ICollection, and IEnumerable interfaces. Benefits of using IBindingList include support for change notifications when the list is modified.
It has a ListChanged event, which is fired when any data changes
If the collection supports changes, it should also support firing a ListChanged event when the collection changes.
To indicate this, it should return true from the SupportsChangeNotification property.
When items are added or removed from the collection, the Grid Grouping control is notified of these changes and updates itself automatically.
This sample implements the INotifiedPropertyChanged interface to make the collection aware of property changes.
Benefits
The benefits of using IBindingList
include support for change notifications when the list is modified.
It does have a ListChanged event, which will be
fired when any data changes. If the collection supports changes, it
should also support firing a ListChanged event when the
collection changes. To indicate that, it should return true
from the SupportsChangeNotification property. Hence, when
items are added or removed from the collection, the Grid Grouping
control will be notified of these changes and will update itself
automatically.
This sample also implements the INotifiedPropertyChanged interface used to make the collection aware of any property changes.
Interactive Features:
Follow these steps to experience the benefits of the ListChanged event.
Implement the ListChanged event.
public event System.ComponentModel.ListChangedEventHandler ListChanged; void RaiseListChanged(ListChangedType type, int index) { if (ListChanged != null) ListChanged(this, new ListChangedEventArgs(type, index)); }
The SupportChangeNotification property should be made to return true.
public bool SupportsChangeNotification { get { return true; } }
Raise the ListChanged event when there is a change in the list.
public int Add(object value) { int count = list.Add(value); RaiseListChanged(ListChangedType.ItemAdded, list.Count-1); return count; } public void RemoveAt(int index) { list.RemoveAt(index); RaiseListChanged(ListChangedType.ItemDeleted, index); } public void Insert(int index, object value) { list.Insert(index, value); RaiseListChanged(ListChangedType.ItemAdded, index); } public void Remove(object value) { int index = list.IndexOf(value); list.Remove(value); RaiseListChanged(ListChangedType.ItemDeleted, index); }