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