1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/External/Aga.Controls/Tree/TreeColumnCollection.cs Sun May 27 15:16:19 2012 +0000
1.3 @@ -0,0 +1,98 @@
1.4 +using System;
1.5 +using System.Collections.Generic;
1.6 +using System.Text;
1.7 +using System.Collections.ObjectModel;
1.8 +using System.ComponentModel;
1.9 +using System.Windows.Forms;
1.10 +
1.11 +namespace Aga.Controls.Tree
1.12 +{
1.13 + internal class TreeColumnCollection : Collection<TreeColumn>
1.14 + {
1.15 + private TreeViewAdv _treeView;
1.16 +
1.17 + public TreeColumnCollection(TreeViewAdv treeView)
1.18 + {
1.19 + _treeView = treeView;
1.20 + }
1.21 +
1.22 + protected override void InsertItem(int index, TreeColumn item)
1.23 + {
1.24 + base.InsertItem(index, item);
1.25 + BindEvents(item);
1.26 + _treeView.UpdateColumns();
1.27 + }
1.28 +
1.29 + protected override void RemoveItem(int index)
1.30 + {
1.31 + UnbindEvents(this[index]);
1.32 + base.RemoveItem(index);
1.33 + _treeView.UpdateColumns();
1.34 + }
1.35 +
1.36 + protected override void SetItem(int index, TreeColumn item)
1.37 + {
1.38 + UnbindEvents(this[index]);
1.39 + base.SetItem(index, item);
1.40 + item.Owner = this;
1.41 + BindEvents(item);
1.42 + _treeView.UpdateColumns();
1.43 + }
1.44 +
1.45 + protected override void ClearItems()
1.46 + {
1.47 + foreach (TreeColumn c in Items)
1.48 + UnbindEvents(c);
1.49 + Items.Clear();
1.50 + _treeView.UpdateColumns();
1.51 + }
1.52 +
1.53 + private void BindEvents(TreeColumn item)
1.54 + {
1.55 + item.Owner = this;
1.56 + item.HeaderChanged += HeaderChanged;
1.57 + item.IsVisibleChanged += IsVisibleChanged;
1.58 + item.WidthChanged += WidthChanged;
1.59 + item.SortOrderChanged += SortOrderChanged;
1.60 + }
1.61 +
1.62 + private void UnbindEvents(TreeColumn item)
1.63 + {
1.64 + item.Owner = null;
1.65 + item.HeaderChanged -= HeaderChanged;
1.66 + item.IsVisibleChanged -= IsVisibleChanged;
1.67 + item.WidthChanged -= WidthChanged;
1.68 + item.SortOrderChanged -= SortOrderChanged;
1.69 + }
1.70 +
1.71 + void SortOrderChanged(object sender, EventArgs e)
1.72 + {
1.73 + TreeColumn changed = sender as TreeColumn;
1.74 + //Only one column at a time can have a sort property set
1.75 + if (changed.SortOrder != SortOrder.None)
1.76 + {
1.77 + foreach (TreeColumn col in this)
1.78 + {
1.79 + if (col != changed)
1.80 + col.SortOrder = SortOrder.None;
1.81 + }
1.82 + }
1.83 + _treeView.UpdateHeaders();
1.84 + }
1.85 +
1.86 + void WidthChanged(object sender, EventArgs e)
1.87 + {
1.88 + _treeView.ChangeColumnWidth(sender as TreeColumn);
1.89 + }
1.90 +
1.91 + void IsVisibleChanged(object sender, EventArgs e)
1.92 + {
1.93 + _treeView.FullUpdate();
1.94 + }
1.95 +
1.96 + void HeaderChanged(object sender, EventArgs e)
1.97 + {
1.98 + _treeView.UpdateView();
1.99 + }
1.100 + }
1.101 +}