using System; using System.Collections.Generic; using System.Collections.ObjectModel; namespace Nuclex.Windows.Forms { /// Collection of controls embedded in a ListView public class ListViewEmbeddedControlCollection : Collection { #region class ListViewEmbeddedControlEventArgs /// Arguments class for events that need to pass a control public class ListViewEmbeddedControlEventArgs : EventArgs { /// Initializes a new event arguments supplier /// Control to be supplied to the event handler public ListViewEmbeddedControlEventArgs(ListViewEmbeddedControl embeddedControl) { this.embeddedControl = embeddedControl; } /// Obtains the control the event arguments are carrying public ListViewEmbeddedControl EmbeddedControl { get { return this.embeddedControl; } } /// Control that's passed to the event handler private ListViewEmbeddedControl embeddedControl; } #endregion // class ListViewEmbeddedControlEventArgs /// Raised when a control has been added to the collection public event EventHandler Added; /// Raised when a control is removed from the collection public event EventHandler Removed; /// Raised the collection is about to be cleared public event EventHandler Clearing; /// Removes all elements from the ListViewEmbeddedControlCollection protected override void ClearItems() { OnClearing(); base.ClearItems(); } /// /// Inserts an element into the ListViewEmbeddedControlCollection at the specified index /// /// /// The object to insert. The value can be null for reference types /// /// The zero-based index at which item should be inserted protected override void InsertItem(int index, ListViewEmbeddedControl item) { base.InsertItem(index, item); OnAdded(item); } /// /// Removes the element at the specified index of the ListViewEmbeddedControlCollection /// /// The zero-based index of the element to remove protected override void RemoveItem(int index) { ListViewEmbeddedControl control = base[index]; base.RemoveItem(index); OnRemoved(control); } /// Replaces the element at the specified index /// /// The new value for the element at the specified index. The value can be null /// for reference types /// /// The zero-based index of the element to replace protected override void SetItem(int index, ListViewEmbeddedControl item) { ListViewEmbeddedControl control = base[index]; base.SetItem(index, item); OnRemoved(control); OnAdded(item); } /// Fires the Added event /// /// Embedded control that has been added to the collection /// protected virtual void OnAdded(ListViewEmbeddedControl embeddedControl) { if(Added != null) Added(this, new ListViewEmbeddedControlEventArgs(embeddedControl)); } /// Fires the Removed event /// /// Embedded control that has been removed from the collection /// protected virtual void OnRemoved(ListViewEmbeddedControl embeddedControl) { if(Removed != null) Removed(this, new ListViewEmbeddedControlEventArgs(embeddedControl)); } /// Fires the Clearing event protected virtual void OnClearing() { if(Clearing != null) Clearing(this, EventArgs.Empty); } } } // namespace Nuclex.Windows.Forms