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