moel@345: using System; moel@345: using System.Collections.Generic; moel@345: using System.Text; moel@345: using System.Collections.ObjectModel; moel@345: using System.ComponentModel; moel@345: using System.Windows.Forms; moel@345: moel@345: namespace Aga.Controls.Tree moel@345: { moel@345: internal class TreeColumnCollection : Collection moel@345: { moel@345: private TreeViewAdv _treeView; moel@345: moel@345: public TreeColumnCollection(TreeViewAdv treeView) moel@345: { moel@345: _treeView = treeView; moel@345: } moel@345: moel@345: protected override void InsertItem(int index, TreeColumn item) moel@345: { moel@345: base.InsertItem(index, item); moel@345: BindEvents(item); moel@345: _treeView.UpdateColumns(); moel@345: } moel@345: moel@345: protected override void RemoveItem(int index) moel@345: { moel@345: UnbindEvents(this[index]); moel@345: base.RemoveItem(index); moel@345: _treeView.UpdateColumns(); moel@345: } moel@345: moel@345: protected override void SetItem(int index, TreeColumn item) moel@345: { moel@345: UnbindEvents(this[index]); moel@345: base.SetItem(index, item); moel@345: item.Owner = this; moel@345: BindEvents(item); moel@345: _treeView.UpdateColumns(); moel@345: } moel@345: moel@345: protected override void ClearItems() moel@345: { moel@345: foreach (TreeColumn c in Items) moel@345: UnbindEvents(c); moel@345: Items.Clear(); moel@345: _treeView.UpdateColumns(); moel@345: } moel@345: moel@345: private void BindEvents(TreeColumn item) moel@345: { moel@345: item.Owner = this; moel@345: item.HeaderChanged += HeaderChanged; moel@345: item.IsVisibleChanged += IsVisibleChanged; moel@345: item.WidthChanged += WidthChanged; moel@345: item.SortOrderChanged += SortOrderChanged; moel@345: } moel@345: moel@345: private void UnbindEvents(TreeColumn item) moel@345: { moel@345: item.Owner = null; moel@345: item.HeaderChanged -= HeaderChanged; moel@345: item.IsVisibleChanged -= IsVisibleChanged; moel@345: item.WidthChanged -= WidthChanged; moel@345: item.SortOrderChanged -= SortOrderChanged; moel@345: } moel@345: moel@345: void SortOrderChanged(object sender, EventArgs e) moel@345: { moel@345: TreeColumn changed = sender as TreeColumn; moel@345: //Only one column at a time can have a sort property set moel@345: if (changed.SortOrder != SortOrder.None) moel@345: { moel@345: foreach (TreeColumn col in this) moel@345: { moel@345: if (col != changed) moel@345: col.SortOrder = SortOrder.None; moel@345: } moel@345: } moel@345: _treeView.UpdateHeaders(); moel@345: } moel@345: moel@345: void WidthChanged(object sender, EventArgs e) moel@345: { moel@345: _treeView.ChangeColumnWidth(sender as TreeColumn); moel@345: } moel@345: moel@345: void IsVisibleChanged(object sender, EventArgs e) moel@345: { moel@345: _treeView.FullUpdate(); moel@345: } moel@345: moel@345: void HeaderChanged(object sender, EventArgs e) moel@345: { moel@345: _treeView.UpdateView(); moel@345: } moel@345: } moel@345: }