The ContainerListView control should now be working the way it way intended to
git-svn-id: file:///srv/devel/repo-conversion/nuwi@2 d2e56fa2-650e-0410-a79f-9358c0239efd
This commit is contained in:
parent
a82371fa93
commit
ed2eb1443e
|
@ -20,37 +20,21 @@ namespace Nuclex.Windows.Forms {
|
|||
/// </remarks>
|
||||
public partial class ContainerListView : System.Windows.Forms.ListView {
|
||||
|
||||
#region struct EmbeddedControl
|
||||
|
||||
/// <summary>Informationen über ein ins ListView eingebettetes Steuerelement</summary>
|
||||
private struct EmbeddedControl {
|
||||
/// <summary>Steuerelement das im ListView eingebetttr ist</summary>
|
||||
public Control Control;
|
||||
/// <summary>Spalte in der das Control eingebettet ist</summary>
|
||||
public int Column;
|
||||
/// <summary>Zeile in der das Control eingebettet ist</summary>
|
||||
public int Row;
|
||||
/// <summary>Wie das Control in der ListView-Zelle angedockt ist</summary>
|
||||
public DockStyle Dock;
|
||||
/// <summary>Das ListView-Element in dem sich das Control befindet</summary>
|
||||
public ListViewItem Item;
|
||||
}
|
||||
|
||||
#endregion // struct EmbeddedControl
|
||||
|
||||
/// <summary>Initialisiert ein neues ListView-Steuerelement</summary>
|
||||
public ContainerListView() {
|
||||
this.embeddedControlClickedHandler = new EventHandler(embeddedControlClicked);
|
||||
|
||||
this.embeddedControls = new ListViewEmbeddedControlCollection();
|
||||
this.embeddedControls.EmbeddedControlAdded +=
|
||||
this.embeddedControls.Added +=
|
||||
new EventHandler<ListViewEmbeddedControlCollection.ListViewEmbeddedControlEventArgs>(
|
||||
embeddedControlAdded
|
||||
);
|
||||
this.embeddedControls.EmbeddedControlRemoved +=
|
||||
this.embeddedControls.Removed +=
|
||||
new EventHandler<ListViewEmbeddedControlCollection.ListViewEmbeddedControlEventArgs>(
|
||||
embeddedControlRemoved
|
||||
);
|
||||
this.embeddedControls.Clearing +=
|
||||
new EventHandler(embeddedControlsClearing);
|
||||
|
||||
InitializeComponent();
|
||||
|
||||
|
@ -58,6 +42,22 @@ namespace Nuclex.Windows.Forms {
|
|||
base.AllowColumnReorder = false;
|
||||
}
|
||||
|
||||
/// <summary>Called when the list of embedded controls has been cleared</summary>
|
||||
/// <param name="sender">Collection that has been cleared of its controls</param>
|
||||
/// <param name="e">Not used</param>
|
||||
private void embeddedControlsClearing(object sender, EventArgs e) {
|
||||
this.BeginUpdate();
|
||||
try {
|
||||
foreach(ListViewEmbeddedControl embeddedControl in this.embeddedControls) {
|
||||
embeddedControl.Control.Click -= this.embeddedControlClickedHandler;
|
||||
this.Controls.Remove(embeddedControl.Control);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
this.EndUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Called when a control gets removed from the embedded controls list</summary>
|
||||
/// <param name="sender">List from which the control has been removed</param>
|
||||
/// <param name="e">Event arguments providing a reference to the removed control</param>
|
||||
|
@ -101,26 +101,20 @@ namespace Nuclex.Windows.Forms {
|
|||
}
|
||||
}
|
||||
|
||||
private int[] GetColumnOrder() {
|
||||
int[] order = new int[this.Columns.Count];
|
||||
|
||||
for(int i = 0; i < this.Columns.Count; ++i)
|
||||
order[this.Columns[i].DisplayIndex] = i;
|
||||
|
||||
return order;
|
||||
}
|
||||
|
||||
/// <summary>Calculates the boundaries of a cell in the list view</summary>
|
||||
/// <param name="item">Item in the list view from which to calculate the cell</param>
|
||||
/// <param name="subItem">Index der cell whose boundaries to calculate</param>
|
||||
/// <returns>The boundaries of the specified list view cell</returns>
|
||||
/// <exception cref="IndexOutOfRangeException">
|
||||
/// When the specified sub item index is not in the range of valid sub items
|
||||
/// </exception>
|
||||
protected Rectangle GetSubItemBounds(ListViewItem item, int subItem) {
|
||||
|
||||
int[] order = GetColumnOrder();
|
||||
if (order == null) // No Columns
|
||||
if(order == null) // No Columns
|
||||
return Rectangle.Empty;
|
||||
|
||||
if (subItem >= order.Length)
|
||||
if(subItem >= order.Length)
|
||||
throw new IndexOutOfRangeException("SubItem " + subItem + " out of range");
|
||||
|
||||
// Rahmen des gesamten ListViewItems ermitteln, inklusive aller SubItems
|
||||
|
@ -132,9 +126,9 @@ namespace Nuclex.Windows.Forms {
|
|||
// Columns[order[i]] statt Columns[i] verwenden!
|
||||
ColumnHeader columnHeader;
|
||||
int i;
|
||||
for (i = 0; i < order.Length; ++i) {
|
||||
for(i = 0; i < order.Length; ++i) {
|
||||
columnHeader = this.Columns[order[i]];
|
||||
if (columnHeader.Index == subItem)
|
||||
if(columnHeader.Index == subItem)
|
||||
break;
|
||||
|
||||
subItemX += columnHeader.Width;
|
||||
|
@ -146,6 +140,17 @@ namespace Nuclex.Windows.Forms {
|
|||
|
||||
}
|
||||
|
||||
/// <summary>Obtains the current column order of the list</summary>
|
||||
/// <returns>An array indicating the order of the list's columns</returns>
|
||||
private int[] GetColumnOrder() {
|
||||
int[] order = new int[this.Columns.Count];
|
||||
|
||||
for(int i = 0; i < this.Columns.Count; ++i)
|
||||
order[this.Columns[i].DisplayIndex] = i;
|
||||
|
||||
return order;
|
||||
}
|
||||
|
||||
/// <summary>Event handler for when embedded controls are clicked on</summary>
|
||||
private EventHandler embeddedControlClickedHandler;
|
||||
/// <summary>Controls being embedded in this ListView</summary>
|
||||
|
|
|
@ -17,17 +17,17 @@ namespace Nuclex.Windows.Forms {
|
|||
this.column = column;
|
||||
}
|
||||
|
||||
/// <summary>Control that has been embedded in a ListView</summary>
|
||||
/// <summary>Control that is being embedded in the ListView</summary>
|
||||
public Control Control {
|
||||
get { return this.control; }
|
||||
}
|
||||
|
||||
/// <summary>Row in the ListView the control has been embedded in</summary>
|
||||
/// <summary>Row the control has been embedded in</summary>
|
||||
public int Row {
|
||||
get { return this.row; }
|
||||
}
|
||||
|
||||
/// <summary>Column in the ListView the control has been embedded in</summary>
|
||||
/// <summary>Column the control has been embedded in</summary>
|
||||
public int Column {
|
||||
get { return this.column; }
|
||||
}
|
||||
|
@ -38,6 +38,7 @@ namespace Nuclex.Windows.Forms {
|
|||
private int row;
|
||||
/// <summary>Column where the control is embedded</summary>
|
||||
private int column;
|
||||
|
||||
}
|
||||
|
||||
} // namespace Nuclex.Windows.Forms
|
||||
|
|
|
@ -31,12 +31,16 @@ namespace Nuclex.Windows.Forms {
|
|||
#endregion // class ListViewEmbeddedControlEventArgs
|
||||
|
||||
/// <summary>Raised when a control has been added to the collection</summary>
|
||||
public event EventHandler<ListViewEmbeddedControlEventArgs> EmbeddedControlAdded;
|
||||
public event EventHandler<ListViewEmbeddedControlEventArgs> Added;
|
||||
/// <summary>Raised when a control is removed from the collection</summary>
|
||||
public event EventHandler<ListViewEmbeddedControlEventArgs> EmbeddedControlRemoved;
|
||||
public event EventHandler<ListViewEmbeddedControlEventArgs> Removed;
|
||||
/// <summary>Raised the collection is about to be cleared</summary>
|
||||
public event EventHandler Clearing;
|
||||
|
||||
/// <summary>Removes all elements from the ListViewEmbeddedControlCollection</summary>
|
||||
protected override void ClearItems() {
|
||||
OnClearing();
|
||||
|
||||
base.ClearItems();
|
||||
}
|
||||
|
||||
|
@ -49,6 +53,8 @@ namespace Nuclex.Windows.Forms {
|
|||
/// <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);
|
||||
|
||||
OnAdded(item);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -56,7 +62,11 @@ namespace Nuclex.Windows.Forms {
|
|||
/// </summary>
|
||||
/// <param name="index">The zero-based index of the element to remove</param>
|
||||
protected override void RemoveItem(int index) {
|
||||
ListViewEmbeddedControl control = base[index];
|
||||
|
||||
base.RemoveItem(index);
|
||||
|
||||
OnRemoved(control);
|
||||
}
|
||||
|
||||
/// <summary>Replaces the element at the specified index</summary>
|
||||
|
@ -66,25 +76,36 @@ namespace Nuclex.Windows.Forms {
|
|||
/// </param>
|
||||
/// <param name="item">The zero-based index of the element to replace</param>
|
||||
protected override void SetItem(int index, ListViewEmbeddedControl item) {
|
||||
ListViewEmbeddedControl control = base[index];
|
||||
|
||||
base.SetItem(index, item);
|
||||
|
||||
OnRemoved(control);
|
||||
OnAdded(item);
|
||||
}
|
||||
|
||||
/// <summary>Fires the EmbeddedControlAdded event</summary>
|
||||
/// <summary>Fires the Added event</summary>
|
||||
/// <param name="embeddedControl">
|
||||
/// Embedded control that has been added to the collection
|
||||
/// </param>
|
||||
protected virtual void OnEmbeddedControlAdded(ListViewEmbeddedControl embeddedControl) {
|
||||
if(EmbeddedControlAdded != null)
|
||||
EmbeddedControlAdded(this, new ListViewEmbeddedControlEventArgs(embeddedControl));
|
||||
protected virtual void OnAdded(ListViewEmbeddedControl embeddedControl) {
|
||||
if(Added != null)
|
||||
Added(this, new ListViewEmbeddedControlEventArgs(embeddedControl));
|
||||
}
|
||||
|
||||
/// <summary>Fires the EmbeddedControlRemoved event</summary>
|
||||
/// <summary>Fires the Removed event</summary>
|
||||
/// <param name="embeddedControl">
|
||||
/// Embedded control that has been removed from the collection
|
||||
/// </param>
|
||||
protected virtual void OnEmbeddedControlRemoved(ListViewEmbeddedControl embeddedControl) {
|
||||
if(EmbeddedControlRemoved != null)
|
||||
EmbeddedControlRemoved(this, new ListViewEmbeddedControlEventArgs(embeddedControl));
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user