The implementation of a custom collection through a collection base is simpler when derived from the IList.
Features:
Changing the content of the collection will not update the grid.
Set grid.Table.TableDirty = true after making changes directly to the underlying collection since no ListChanged event is raised in this limited implementation.
The Grid Grouping control relies upon the IBindingList.ListChanged event to react to changes in the underlying data.
If this event is not raised by the data collection, then set Table.TableDirty = true and force the grid to refresh itself.
A more robust implementation would also implement IBindingList and listen to the collection-base notifications such as OnClear, OnInsert, etc.
Also, raise the IBindingList.ListChanged event with appropriate arguments to notify event listeners to changes.
C# code
public class DataCollection : System.Collections.CollectionBase { public DataCollection() { } public void Add(Data info) { this.List.Add(info); } public void Remove(Data info) { this.List.Remove(info); } public Data this[int index] { get { return (Data)base.List[index]; } } }
VB Code
Public Class DataCollection : Inherits System.Collections.CollectionBase Public Sub New() End Sub Public Sub Add(ByVal info As Data) Me.List.Add(info) End Sub Public Sub Remove(ByVal info As Data) Me.List.Remove(info) End Sub Public ReadOnly Default Property Item(ByVal index As Integer) As Data Get Return CType(MyBase.List(index), Data) End Get End Property End Class
Note: Changing the contents of the collection will not update the grid.
For this reason, you should always set grid.Table.TableDirty = true after making changes directly to the underlying collection since no ListChanged event is raised in this limited implementation. The Grid Grouping control relies upon the IBindingList.ListChanged event to react to changes in the underlying data. If this event is not raised by the data collection, then you can set Table.TableDirty = true to force the grid to refresh itself.
A more robust implementation would also implement IBindingList and listen to the collection-base notifications such as OnClear, OnInsert, etc., and raise the IBindingList.ListChanged event with appropriate arguments to notify event listeners to changes.