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>
|
/// </remarks>
|
||||||
public partial class ContainerListView : System.Windows.Forms.ListView {
|
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>
|
/// <summary>Initialisiert ein neues ListView-Steuerelement</summary>
|
||||||
public ContainerListView() {
|
public ContainerListView() {
|
||||||
this.embeddedControlClickedHandler = new EventHandler(embeddedControlClicked);
|
this.embeddedControlClickedHandler = new EventHandler(embeddedControlClicked);
|
||||||
|
|
||||||
this.embeddedControls = new ListViewEmbeddedControlCollection();
|
this.embeddedControls = new ListViewEmbeddedControlCollection();
|
||||||
this.embeddedControls.EmbeddedControlAdded +=
|
this.embeddedControls.Added +=
|
||||||
new EventHandler<ListViewEmbeddedControlCollection.ListViewEmbeddedControlEventArgs>(
|
new EventHandler<ListViewEmbeddedControlCollection.ListViewEmbeddedControlEventArgs>(
|
||||||
embeddedControlAdded
|
embeddedControlAdded
|
||||||
);
|
);
|
||||||
this.embeddedControls.EmbeddedControlRemoved +=
|
this.embeddedControls.Removed +=
|
||||||
new EventHandler<ListViewEmbeddedControlCollection.ListViewEmbeddedControlEventArgs>(
|
new EventHandler<ListViewEmbeddedControlCollection.ListViewEmbeddedControlEventArgs>(
|
||||||
embeddedControlRemoved
|
embeddedControlRemoved
|
||||||
);
|
);
|
||||||
|
this.embeddedControls.Clearing +=
|
||||||
|
new EventHandler(embeddedControlsClearing);
|
||||||
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
|
@ -58,6 +42,22 @@ namespace Nuclex.Windows.Forms {
|
||||||
base.AllowColumnReorder = false;
|
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>
|
/// <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="sender">List from which the control has been removed</param>
|
||||||
/// <param name="e">Event arguments providing a reference to the removed control</param>
|
/// <param name="e">Event arguments providing a reference to the removed control</param>
|
||||||
|
@ -92,7 +92,7 @@ namespace Nuclex.Windows.Forms {
|
||||||
foreach(ListViewEmbeddedControl embeddedControl in this.embeddedControls) {
|
foreach(ListViewEmbeddedControl embeddedControl in this.embeddedControls) {
|
||||||
if(ReferenceEquals(embeddedControl.Control, sender)) {
|
if(ReferenceEquals(embeddedControl.Control, sender)) {
|
||||||
if((embeddedControl.Row > 0) && (embeddedControl.Row < Items.Count))
|
if((embeddedControl.Row > 0) && (embeddedControl.Row < Items.Count))
|
||||||
Items[embeddedControl.Row].Selected = true;
|
Items[embeddedControl.Row].Selected = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,48 @@ namespace Nuclex.Windows.Forms {
|
||||||
this.EndUpdate();
|
this.EndUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <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
|
||||||
|
return Rectangle.Empty;
|
||||||
|
|
||||||
|
if(subItem >= order.Length)
|
||||||
|
throw new IndexOutOfRangeException("SubItem " + subItem + " out of range");
|
||||||
|
|
||||||
|
// Rahmen des gesamten ListViewItems ermitteln, inklusive aller SubItems
|
||||||
|
Rectangle itemBounds = item.GetBounds(ItemBoundsPortion.Entire);
|
||||||
|
int subItemX = itemBounds.Left;
|
||||||
|
|
||||||
|
// Horizontale Position des SubItems berechnen
|
||||||
|
// Da die Spaltenreihenfolge geändert werden kann müssen wir
|
||||||
|
// Columns[order[i]] statt Columns[i] verwenden!
|
||||||
|
ColumnHeader columnHeader;
|
||||||
|
int i;
|
||||||
|
for(i = 0; i < order.Length; ++i) {
|
||||||
|
columnHeader = this.Columns[order[i]];
|
||||||
|
if(columnHeader.Index == subItem)
|
||||||
|
break;
|
||||||
|
|
||||||
|
subItemX += columnHeader.Width;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Rectangle(
|
||||||
|
subItemX, itemBounds.Top, this.Columns[order[i]].Width, itemBounds.Height
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <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() {
|
private int[] GetColumnOrder() {
|
||||||
int[] order = new int[this.Columns.Count];
|
int[] order = new int[this.Columns.Count];
|
||||||
|
|
||||||
|
@ -110,42 +151,6 @@ namespace Nuclex.Windows.Forms {
|
||||||
return order;
|
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>
|
|
||||||
protected Rectangle GetSubItemBounds(ListViewItem item, int subItem) {
|
|
||||||
|
|
||||||
int[] order = GetColumnOrder();
|
|
||||||
if (order == null) // No Columns
|
|
||||||
return Rectangle.Empty;
|
|
||||||
|
|
||||||
if (subItem >= order.Length)
|
|
||||||
throw new IndexOutOfRangeException("SubItem " + subItem + " out of range");
|
|
||||||
|
|
||||||
// Rahmen des gesamten ListViewItems ermitteln, inklusive aller SubItems
|
|
||||||
Rectangle itemBounds = item.GetBounds(ItemBoundsPortion.Entire);
|
|
||||||
int subItemX = itemBounds.Left;
|
|
||||||
|
|
||||||
// Horizontale Position des SubItems berechnen
|
|
||||||
// Da die Spaltenreihenfolge geändert werden kann müssen wir
|
|
||||||
// Columns[order[i]] statt Columns[i] verwenden!
|
|
||||||
ColumnHeader columnHeader;
|
|
||||||
int i;
|
|
||||||
for (i = 0; i < order.Length; ++i) {
|
|
||||||
columnHeader = this.Columns[order[i]];
|
|
||||||
if (columnHeader.Index == subItem)
|
|
||||||
break;
|
|
||||||
|
|
||||||
subItemX += columnHeader.Width;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Rectangle(
|
|
||||||
subItemX, itemBounds.Top, this.Columns[order[i]].Width, itemBounds.Height
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Event handler for when embedded controls are clicked on</summary>
|
/// <summary>Event handler for when embedded controls are clicked on</summary>
|
||||||
private EventHandler embeddedControlClickedHandler;
|
private EventHandler embeddedControlClickedHandler;
|
||||||
/// <summary>Controls being embedded in this ListView</summary>
|
/// <summary>Controls being embedded in this ListView</summary>
|
||||||
|
|
|
@ -17,17 +17,17 @@ namespace Nuclex.Windows.Forms {
|
||||||
this.column = column;
|
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 {
|
public Control Control {
|
||||||
get { return this.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 {
|
public int Row {
|
||||||
get { return this.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 {
|
public int Column {
|
||||||
get { return this.column; }
|
get { return this.column; }
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,7 @@ namespace Nuclex.Windows.Forms {
|
||||||
private int row;
|
private int row;
|
||||||
/// <summary>Column where the control is embedded</summary>
|
/// <summary>Column where the control is embedded</summary>
|
||||||
private int column;
|
private int column;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Nuclex.Windows.Forms
|
} // namespace Nuclex.Windows.Forms
|
||||||
|
|
|
@ -31,12 +31,16 @@ namespace Nuclex.Windows.Forms {
|
||||||
#endregion // class ListViewEmbeddedControlEventArgs
|
#endregion // class ListViewEmbeddedControlEventArgs
|
||||||
|
|
||||||
/// <summary>Raised when a control has been added to the collection</summary>
|
/// <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>
|
/// <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>
|
/// <summary>Removes all elements from the ListViewEmbeddedControlCollection</summary>
|
||||||
protected override void ClearItems() {
|
protected override void ClearItems() {
|
||||||
|
OnClearing();
|
||||||
|
|
||||||
base.ClearItems();
|
base.ClearItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,6 +53,8 @@ namespace Nuclex.Windows.Forms {
|
||||||
/// <param name="item">The zero-based index at which item should be inserted</param>
|
/// <param name="item">The zero-based index at which item should be inserted</param>
|
||||||
protected override void InsertItem(int index, ListViewEmbeddedControl item) {
|
protected override void InsertItem(int index, ListViewEmbeddedControl item) {
|
||||||
base.InsertItem(index, item);
|
base.InsertItem(index, item);
|
||||||
|
|
||||||
|
OnAdded(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -56,7 +62,11 @@ namespace Nuclex.Windows.Forms {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="index">The zero-based index of the element to remove</param>
|
/// <param name="index">The zero-based index of the element to remove</param>
|
||||||
protected override void RemoveItem(int index) {
|
protected override void RemoveItem(int index) {
|
||||||
|
ListViewEmbeddedControl control = base[index];
|
||||||
|
|
||||||
base.RemoveItem(index);
|
base.RemoveItem(index);
|
||||||
|
|
||||||
|
OnRemoved(control);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Replaces the element at the specified index</summary>
|
/// <summary>Replaces the element at the specified index</summary>
|
||||||
|
@ -66,25 +76,36 @@ namespace Nuclex.Windows.Forms {
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <param name="item">The zero-based index of the element to replace</param>
|
/// <param name="item">The zero-based index of the element to replace</param>
|
||||||
protected override void SetItem(int index, ListViewEmbeddedControl item) {
|
protected override void SetItem(int index, ListViewEmbeddedControl item) {
|
||||||
|
ListViewEmbeddedControl control = base[index];
|
||||||
|
|
||||||
base.SetItem(index, item);
|
base.SetItem(index, item);
|
||||||
|
|
||||||
|
OnRemoved(control);
|
||||||
|
OnAdded(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Fires the EmbeddedControlAdded event</summary>
|
/// <summary>Fires the Added event</summary>
|
||||||
/// <param name="embeddedControl">
|
/// <param name="embeddedControl">
|
||||||
/// Embedded control that has been added to the collection
|
/// Embedded control that has been added to the collection
|
||||||
/// </param>
|
/// </param>
|
||||||
protected virtual void OnEmbeddedControlAdded(ListViewEmbeddedControl embeddedControl) {
|
protected virtual void OnAdded(ListViewEmbeddedControl embeddedControl) {
|
||||||
if(EmbeddedControlAdded != null)
|
if(Added != null)
|
||||||
EmbeddedControlAdded(this, new ListViewEmbeddedControlEventArgs(embeddedControl));
|
Added(this, new ListViewEmbeddedControlEventArgs(embeddedControl));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Fires the EmbeddedControlRemoved event</summary>
|
/// <summary>Fires the Removed event</summary>
|
||||||
/// <param name="embeddedControl">
|
/// <param name="embeddedControl">
|
||||||
/// Embedded control that has been removed from the collection
|
/// Embedded control that has been removed from the collection
|
||||||
/// </param>
|
/// </param>
|
||||||
protected virtual void OnEmbeddedControlRemoved(ListViewEmbeddedControl embeddedControl) {
|
protected virtual void OnRemoved(ListViewEmbeddedControl embeddedControl) {
|
||||||
if(EmbeddedControlRemoved != null)
|
if(Removed != null)
|
||||||
EmbeddedControlRemoved(this, new ListViewEmbeddedControlEventArgs(embeddedControl));
|
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