[Adapdev-commits] Adapdev/src/Adapdev.Windows.Forms SmartTreeView.cs,1.3,1.4
Status: Beta
Brought to you by:
intesar66
From: Sean M. <int...@us...> - 2005-06-05 08:50:43
|
Update of /cvsroot/adapdev/Adapdev/src/Adapdev.Windows.Forms In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31410/src/Adapdev.Windows.Forms Modified Files: SmartTreeView.cs Log Message: Fixed several bugs with SmartTreeView Fixed bugs with TestRunner Index: SmartTreeView.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.Windows.Forms/SmartTreeView.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** SmartTreeView.cs 3 Jun 2005 03:51:19 -0000 1.3 --- SmartTreeView.cs 5 Jun 2005 08:50:33 -0000 1.4 *************** *** 9,12 **** --- 9,14 ---- using System.Text; + public delegate void StateChangedEventHandler(TreeNode node, bool state); + public class SmartTreeView : System.Windows.Forms.TreeView { *************** *** 18,21 **** --- 20,25 ---- private Hashtable state = new Hashtable(); + public event StateChangedEventHandler StateChanged; + public SmartTreeView() { *************** *** 51,54 **** --- 55,60 ---- this.CheckBoxes = true; this.AfterCheck += new System.Windows.Forms.TreeViewEventHandler(this.SmartTreeView_AfterCheck); + this.BeforeCheck += new System.Windows.Forms.TreeViewCancelEventHandler(this.SmartTreeView_BeforeCheck); + } #endregion *************** *** 92,95 **** --- 98,107 ---- treeNode = treeNode.Parent; } + + // Set the state for the topmost node + if(treeNode == this.Nodes[0]) + { + treeNode.Checked = node.Checked; + } } *************** *** 161,173 **** { this.state[this.GetUniqueNodeName(node)] = node.Checked; } ! public void GetState(TreeNode node) { string uniqueName = this.GetUniqueNodeName(node); if(this.state.ContainsKey(uniqueName)) { ! node.Checked = (bool)this.state[uniqueName]; } } --- 173,196 ---- { this.state[this.GetUniqueNodeName(node)] = node.Checked; + this.OnStateChanged(node, node.Checked); } ! public bool GetState(TreeNode node) ! { ! if(this.HasState(node)) ! { ! return (bool)this.state[this.GetUniqueNodeName(node)]; ! } ! return false; ! } ! ! public bool HasState(TreeNode node) { string uniqueName = this.GetUniqueNodeName(node); if(this.state.ContainsKey(uniqueName)) { ! return true; } + return false; } *************** *** 179,195 **** public void LoadState() { foreach(TreeNode node in this.Nodes) { this.LoadState(node); } } protected void LoadState(TreeNode node) { - this.GetState(node); foreach(TreeNode child in node.Nodes) { this.LoadState(child); } } } --- 202,234 ---- public void LoadState() { + this.disableAfterSelect = true; foreach(TreeNode node in this.Nodes) { this.LoadState(node); } + this.disableAfterSelect = false; + } + + private void SmartTreeView_BeforeCheck(object sender, System.Windows.Forms.TreeViewCancelEventArgs e) + { + //Console.WriteLine("{0} has a parent? {1}", e.Node.Text, e.Node.Parent != null); } protected void LoadState(TreeNode node) { foreach(TreeNode child in node.Nodes) { this.LoadState(child); } + node.Checked = this.GetState(node); + } + + protected virtual void OnStateChanged(TreeNode node, bool state) + { + if (StateChanged != null) + { + //Invokes the delegates. + StateChanged(node, state); + } } } |