author | moel.mich |
Sun, 27 May 2012 16:50:01 +0000 | |
changeset 347 | d043dac9f34e |
permissions | -rw-r--r-- |
moel@345 | 1 |
using System; |
moel@345 | 2 |
using System.Collections.Generic; |
moel@345 | 3 |
using System.Text; |
moel@345 | 4 |
using System.Collections.ObjectModel; |
moel@345 | 5 |
using System.ComponentModel; |
moel@345 | 6 |
using System.Windows.Forms; |
moel@345 | 7 |
|
moel@345 | 8 |
namespace Aga.Controls.Tree |
moel@345 | 9 |
{ |
moel@345 | 10 |
internal class TreeColumnCollection : Collection<TreeColumn> |
moel@345 | 11 |
{ |
moel@345 | 12 |
private TreeViewAdv _treeView; |
moel@345 | 13 |
|
moel@345 | 14 |
public TreeColumnCollection(TreeViewAdv treeView) |
moel@345 | 15 |
{ |
moel@345 | 16 |
_treeView = treeView; |
moel@345 | 17 |
} |
moel@345 | 18 |
|
moel@345 | 19 |
protected override void InsertItem(int index, TreeColumn item) |
moel@345 | 20 |
{ |
moel@345 | 21 |
base.InsertItem(index, item); |
moel@345 | 22 |
BindEvents(item); |
moel@345 | 23 |
_treeView.UpdateColumns(); |
moel@345 | 24 |
} |
moel@345 | 25 |
|
moel@345 | 26 |
protected override void RemoveItem(int index) |
moel@345 | 27 |
{ |
moel@345 | 28 |
UnbindEvents(this[index]); |
moel@345 | 29 |
base.RemoveItem(index); |
moel@345 | 30 |
_treeView.UpdateColumns(); |
moel@345 | 31 |
} |
moel@345 | 32 |
|
moel@345 | 33 |
protected override void SetItem(int index, TreeColumn item) |
moel@345 | 34 |
{ |
moel@345 | 35 |
UnbindEvents(this[index]); |
moel@345 | 36 |
base.SetItem(index, item); |
moel@345 | 37 |
item.Owner = this; |
moel@345 | 38 |
BindEvents(item); |
moel@345 | 39 |
_treeView.UpdateColumns(); |
moel@345 | 40 |
} |
moel@345 | 41 |
|
moel@345 | 42 |
protected override void ClearItems() |
moel@345 | 43 |
{ |
moel@345 | 44 |
foreach (TreeColumn c in Items) |
moel@345 | 45 |
UnbindEvents(c); |
moel@345 | 46 |
Items.Clear(); |
moel@345 | 47 |
_treeView.UpdateColumns(); |
moel@345 | 48 |
} |
moel@345 | 49 |
|
moel@345 | 50 |
private void BindEvents(TreeColumn item) |
moel@345 | 51 |
{ |
moel@345 | 52 |
item.Owner = this; |
moel@345 | 53 |
item.HeaderChanged += HeaderChanged; |
moel@345 | 54 |
item.IsVisibleChanged += IsVisibleChanged; |
moel@345 | 55 |
item.WidthChanged += WidthChanged; |
moel@345 | 56 |
item.SortOrderChanged += SortOrderChanged; |
moel@345 | 57 |
} |
moel@345 | 58 |
|
moel@345 | 59 |
private void UnbindEvents(TreeColumn item) |
moel@345 | 60 |
{ |
moel@345 | 61 |
item.Owner = null; |
moel@345 | 62 |
item.HeaderChanged -= HeaderChanged; |
moel@345 | 63 |
item.IsVisibleChanged -= IsVisibleChanged; |
moel@345 | 64 |
item.WidthChanged -= WidthChanged; |
moel@345 | 65 |
item.SortOrderChanged -= SortOrderChanged; |
moel@345 | 66 |
} |
moel@345 | 67 |
|
moel@345 | 68 |
void SortOrderChanged(object sender, EventArgs e) |
moel@345 | 69 |
{ |
moel@345 | 70 |
TreeColumn changed = sender as TreeColumn; |
moel@345 | 71 |
//Only one column at a time can have a sort property set |
moel@345 | 72 |
if (changed.SortOrder != SortOrder.None) |
moel@345 | 73 |
{ |
moel@345 | 74 |
foreach (TreeColumn col in this) |
moel@345 | 75 |
{ |
moel@345 | 76 |
if (col != changed) |
moel@345 | 77 |
col.SortOrder = SortOrder.None; |
moel@345 | 78 |
} |
moel@345 | 79 |
} |
moel@345 | 80 |
_treeView.UpdateHeaders(); |
moel@345 | 81 |
} |
moel@345 | 82 |
|
moel@345 | 83 |
void WidthChanged(object sender, EventArgs e) |
moel@345 | 84 |
{ |
moel@345 | 85 |
_treeView.ChangeColumnWidth(sender as TreeColumn); |
moel@345 | 86 |
} |
moel@345 | 87 |
|
moel@345 | 88 |
void IsVisibleChanged(object sender, EventArgs e) |
moel@345 | 89 |
{ |
moel@345 | 90 |
_treeView.FullUpdate(); |
moel@345 | 91 |
} |
moel@345 | 92 |
|
moel@345 | 93 |
void HeaderChanged(object sender, EventArgs e) |
moel@345 | 94 |
{ |
moel@345 | 95 |
_treeView.UpdateView(); |
moel@345 | 96 |
} |
moel@345 | 97 |
} |
moel@345 | 98 |
} |