コード例 #1
0
        /// <include file='doc\TreeNodeCollection.uex' path='docs/doc[@for="TreeNodeCollection.Add1"]/*' />
        /// <devdoc>
        ///     Adds a new child node to this node.  Child node is positioned after siblings.
        /// </devdoc>
        public virtual int Add(TreeNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }
            if (node.handle != IntPtr.Zero)
            {
                throw new ArgumentException(SR.GetString(SR.OnlyOneControl, node.Text), "node");
            }

            // If the TreeView is sorted, index is ignored
            TreeView tv = owner.TreeView;

            if (tv != null && tv.Sorted)
            {
                return(owner.AddSorted(node));
            }

            owner.EnsureCapacity();
            node.parent = owner;
            node.index  = owner.childCount++;
            owner.children[node.index] = node;
            node.Realize();

            if (tv != null && node == tv.selectedNode)
            {
                tv.SelectedNode = node; // communicate this to the handle
            }
            return(node.index);
        }
コード例 #2
0
        private int AddInternal(TreeNode node, int delta)
        {
            ArgumentNullException.ThrowIfNull(node);

            if (node._handle != IntPtr.Zero)
            {
                throw new ArgumentException(string.Format(SR.OnlyOneControl, node.Text), nameof(node));
            }

            // Check for ParentingCycle
            owner.CheckParentingCycle(node);

            // If the TreeView is sorted, index is ignored
            TreeView tv = owner.TreeView;

            if (tv is not null)
            {
                foreach (TreeNode treeNode in node.GetSelfAndChildNodes())
                {
                    KeyboardToolTipStateMachine.Instance.Hook(treeNode, tv.KeyboardToolTip);
                }
            }

            if (tv is not null && tv.Sorted)
            {
                return(owner.AddSorted(node));
            }

            node.parent = owner;
            int fixedIndex = owner.Nodes.FixedIndex;

            if (fixedIndex != -1)
            {
                node.index = fixedIndex + delta;
            }
            else
            {
                //if fixedIndex != -1 capacity was ensured by AddRange
                Debug.Assert(delta == 0, "delta should be 0");
                owner.EnsureCapacity(1);
                node.index = owner.childCount;
            }

            owner.children[node.index] = node;
            owner.childCount++;
            node.Realize(false);

            if (tv is not null && node == tv.selectedNode)
            {
                tv.SelectedNode = node; // communicate this to the handle
            }

            if (tv is not null && tv.TreeViewNodeSorter is not null)
            {
                tv.Sort();
            }

            return(node.index);
        }
コード例 #3
0
        private int AddInternal(TreeNode node, int delta)
        {
            if (node == null)
            {
                throw new ArgumentNullException(nameof(node));
            }
            if (node.handle != IntPtr.Zero)
            {
                throw new ArgumentException(string.Format(SR.OnlyOneControl, node.Text), "node");
            }

            // Check for ParentingCycle
            owner.CheckParentingCycle(node);

            // If the TreeView is sorted, index is ignored
            TreeView tv = owner.TreeView;

            if (tv != null && tv.Sorted)
            {
                return(owner.AddSorted(node));
            }
            node.parent = owner;
            int fixedIndex = owner.Nodes.FixedIndex;

            if (fixedIndex != -1)
            {
                node.index = fixedIndex + delta;
            }
            else
            {
                //if fixedIndex != -1 capacity was ensured by AddRange
                Debug.Assert(delta == 0, "delta should be 0");
                owner.EnsureCapacity(1);
                node.index = owner.childCount;
            }
            owner.children[node.index] = node;
            owner.childCount++;
            node.Realize(false);

            if (tv != null && node == tv.selectedNode)
            {
                tv.SelectedNode = node; // communicate this to the handle
            }

            if (tv != null && tv.TreeViewNodeSorter != null)
            {
                tv.Sort();
            }

            return(node.index);
        }
コード例 #4
0
        private int AddInternal(TreeNode node, int delta)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }
            if (node.handle != IntPtr.Zero)
            {
                throw new ArgumentException(System.Windows.Forms.SR.GetString("OnlyOneControl", new object[] { node.Text }), "node");
            }
            TreeView treeView = this.owner.TreeView;

            if ((treeView != null) && treeView.Sorted)
            {
                return(this.owner.AddSorted(node));
            }
            node.parent = this.owner;
            int fixedIndex = this.owner.Nodes.FixedIndex;

            if (fixedIndex != -1)
            {
                node.index = fixedIndex + delta;
            }
            else
            {
                this.owner.EnsureCapacity(1);
                node.index = this.owner.childCount;
            }
            this.owner.children[node.index] = node;
            this.owner.childCount++;
            node.Realize(false);
            if ((treeView != null) && (node == treeView.selectedNode))
            {
                treeView.SelectedNode = node;
            }
            if ((treeView != null) && (treeView.TreeViewNodeSorter != null))
            {
                treeView.Sort();
            }
            return(node.index);
        }
コード例 #5
0
 internal void InsertNodeAt(int index, TreeNode node)
 {
     this.EnsureCapacity(1);
     node.parent = this;
     node.index = index;
     for (int i = this.childCount; i > index; i--)
     {
         TreeNode node2;
         this.children[i] = node2 = this.children[i - 1];
         node2.index = i;
     }
     this.children[index] = node;
     this.childCount++;
     node.Realize(false);
     if ((this.TreeView != null) && (node == this.TreeView.selectedNode))
     {
         this.TreeView.SelectedNode = node;
     }
 }
 private int AddInternal(TreeNode node, int delta)
 {
     if (node == null)
     {
         throw new ArgumentNullException("node");
     }
     if (node.handle != IntPtr.Zero)
     {
         throw new ArgumentException(System.Windows.Forms.SR.GetString("OnlyOneControl", new object[] { node.Text }), "node");
     }
     TreeView treeView = this.owner.TreeView;
     if ((treeView != null) && treeView.Sorted)
     {
         return this.owner.AddSorted(node);
     }
     node.parent = this.owner;
     int fixedIndex = this.owner.Nodes.FixedIndex;
     if (fixedIndex != -1)
     {
         node.index = fixedIndex + delta;
     }
     else
     {
         this.owner.EnsureCapacity(1);
         node.index = this.owner.childCount;
     }
     this.owner.children[node.index] = node;
     this.owner.childCount++;
     node.Realize(false);
     if ((treeView != null) && (node == treeView.selectedNode))
     {
         treeView.SelectedNode = node;
     }
     if ((treeView != null) && (treeView.TreeViewNodeSorter != null))
     {
         treeView.Sort();
     }
     return node.index;
 }
コード例 #7
0
ファイル: TreeNode.cs プロジェクト: JianwenSun/cc
        /// <include file='doc\TreeNode.uex' path='docs/doc[@for="TreeNode.InsertNodeAt"]/*' />
        /// <devdoc>
        ///     Helper function to add node at a given index after all validation has been done
        /// </devdoc>
        /// <internalonly/>
        internal void InsertNodeAt(int index, TreeNode node) {
            EnsureCapacity(1);
            node.parent = this;
            node.index = index;
            for (int i = childCount; i > index; --i) {
                (children[i] = children[i-1]).index = i;
            }
            children[index] = node;
            childCount++;
            node.Realize(false);

            if (TreeView != null && node == TreeView.selectedNode)
                TreeView.SelectedNode = node; // communicate this to the handle
        }
コード例 #8
0
        private int AddInternal(TreeNode node, int delta) {
            if (node == null) {
                throw new ArgumentNullException("node");
            }
            if (node.handle != IntPtr.Zero)
                throw new ArgumentException(SR.GetString(SR.OnlyOneControl, node.Text), "node");

            // If the TreeView is sorted, index is ignored
            TreeView tv = owner.TreeView;
            if (tv != null && tv.Sorted) {
                return owner.AddSorted(node);                
            }
            node.parent = owner;
            int fixedIndex = owner.Nodes.FixedIndex;
            if (fixedIndex != -1) {
                node.index = fixedIndex + delta;
            }
            else {
                //if fixedIndex != -1 capacity was ensured by AddRange 
                Debug.Assert(delta == 0,"delta should be 0");
                owner.EnsureCapacity(1);
                node.index = owner.childCount;
            }
            owner.children[node.index] = node;
            owner.childCount++;
            node.Realize(false);

            if (tv != null && node == tv.selectedNode)
                tv.SelectedNode = node; // communicate this to the handle
            
            if (tv != null && tv.TreeViewNodeSorter != null) {
                tv.Sort();
            }
                
            return node.index;
        }