>>>public class Collection<T> : IEnumerable<T> >>>{ >>> public delegate void EventHandler<TEventArgs>(object sender, TEventArgs e); >>> public delegate void ListClearedEventHandler(object sender, ListClearedEventArgs e); >>> >>> public event ListClearedEventHandler Cleared; >>> public event EventHandler<EventArgs_Generic<T>> ItemAdded; >>> public event EventHandler<EventArgs_Generic<T>> ItemRemoved; >>> >>> List<T> _List = new List<T>(); >>> >>> private int _Count = 0; >>> public int Count >>> { >>> get { return _Count; } >>> } >>> public void Add(T item) >>> { >>> _List.Add(item); >>> _Count++; >>> >>> if (ItemAdded != null) >>> { >>> EventArgs_Generic<T> args = new EventArgs_Generic<T>(item); >>> ItemAdded(this, args); >>> } >>> } >>> public void Clear() >>> { >>> _List.Clear(); >>> _Count = 0; >>> >>> if (Cleared != null) >>> { >>> ListClearedEventArgs args = new ListClearedEventArgs(); >>> Cleared(this, args); >>> } >>> } >>> public void Insert(int index, T item) >>> { >>> _List.Insert(index, item); >>> _Count++; >>> >>> if (ItemAdded != null) >>> { >>> EventArgs_Generic<T> args = new EventArgs_Generic<T>(item); >>> ItemAdded(this, args); >>> } >>> } >>> public void Remove(T item) >>> { >>> _List.Remove(item); >>> _Count--; >>> >>> if (ItemRemoved != null) >>> { >>> EventArgs_Generic<T> args = new EventArgs_Generic<T>(item); >>> ItemRemoved(this, args); >>> } >>> } >>> public T GetItem(int index) >>> { >>> return _List[index]; >>> } >>> >>> IEnumerator<T> IEnumerable<T>.GetEnumerator() >>> { >>> return _List.GetEnumerator(); >>> } >>> IEnumerator IEnumerable.GetEnumerator() >>> { >>> return _List.GetEnumerator(); >>> } >>>} >>> >>>public class EventArgs_Generic<T> : EventArgs >>>{ >>> private T _TargetObject; >>> public T TargetObject >>> { >>> get { return _TargetObject; } >>> } >>> >>> public EventArgs_Generic() >>> { >>> } >>> public EventArgs_Generic(T Target) >>> { >>> _TargetObject = Target; >>> } >>>} >>> >>>public class ListClearedEventArgs : EventArgs >>>{ >>>} >>>>>>
>>>private Collection<MyRow> _Rows = new Collection< MyRow >(); >>>public Collection< MyRow > Rows >>>{ >>> get { return _Rows; } >>> set { _Rows = value; } >>>} >>>>>>
>>>public MyList() >>>{ >>> InitializeComponent(); >>> >>> _Rows.ItemAdded += new Collection<MyRow>.EventHandler<EventArgs_Generic< MyRow >>(_Rows_ItemAdded); >>> _Rows.ItemRemoved += new Collection< MyRow >.EventHandler<EventArgs_Generic< MyRow >>(_Rows_ItemRemoved); >>> _Rows.Cleared += new Collection< MyRow >.ListClearedEventHandler(_Rows_Cleared); >>> >>> _Setup = true; >>>} >>>>>>
>>>private void _Rows_ItemAdded(object sender, EventArgs_Generic< MyRow > e) >>>{ >>>} >>>private void _Rows_ItemRemoved(object sender, EventArgs_Generic< MyRow > e) >>>{ >>>} >>>private void _Rows_Cleared(object sender, ListClearedEventArgs e) >>>{ >>> Controls.Clear(); >>>} >>>>>>
>>>MyList.Rows.Clear(); >>>>>>
_Rows.ItemAdded += _Rows_ItemAdded; >>_Rows.ItemRemoved += _Rows_ItemRemoved; >>_Rows.Cleared += _Rows_Cleared;>
public class MyRow { } public class Test { private Collection<MyRow> _Rows = new Collection<MyRow>(); public Collection<MyRow> Rows { get { return _Rows; } set { _Rows = value; } } public Test() { _Rows.ItemAdded += _Rows_ItemAdded; _Rows.ItemRemoved += _Rows_ItemRemoved; _Rows.Cleared += _Rows_Cleared; } public void TestAction() { Rows.Clear(); Rows.Add(new MyRow()); } private void _Rows_ItemAdded(object sender, EventArgs_Generic<MyRow> e) { } private void _Rows_ItemRemoved(object sender, EventArgs_Generic<MyRow> e) { } private void _Rows_Cleared(object sender, ListClearedEventArgs e) { } }