/// /// Copyright © 2003-2008 JetBrains s.r.o. /// You may distribute under the terms of the GNU General Public License, as published by the Free Software Foundation, version 2 (see License.txt in the repository root folder). /// using System; using System.Windows.Forms; namespace JetBrains.UI.Components.CustomTreeView { /// /// Controls expansion on tree views /// public class ExpansionController { /// /// The tree view /// private TreeView myTreeView; /// /// Enabled flag /// private bool myIsEnabled; public TreeView TreeView { get { return myTreeView; } } public bool IsEnabled { get { return myIsEnabled; } set { myIsEnabled = value; } } public ExpansionController( TreeView treeView ) { myTreeView = treeView; myTreeView.AfterExpand += new TreeViewEventHandler(NodeExpanded); } public static void ExpandNode( TreeNode node, bool select ) { node.Expand(); if (select) node.TreeView.SelectedNode = node; do { node.Expand(); if (node.Nodes.Count > 0) { node = node.Nodes[0]; if (select) node.TreeView.SelectedNode = node; } else break; } while (node.NextNode == null); } private void NodeExpanded( object sender, TreeViewEventArgs e ) { if (myIsEnabled) { ExpandNode (e.Node, false); } } } }