Esempio n. 1
0
        /// <include file='doc\TreeNodeCollection.uex' path='docs/doc[@for="TreeNodeCollection.Insert"]/*' />
        /// <devdoc>
        ///     Inserts a new child node on this node.  Child node is positioned as specified by index.
        /// </devdoc>
        public virtual void Insert(int index, TreeNode 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)
            {
                owner.AddSorted(node);
                return;
            }

            if (index < 0)
            {
                index = 0;
            }
            if (index > owner.childCount)
            {
                index = owner.childCount;
            }
            owner.InsertNodeAt(index, node);
        }
Esempio n. 2
0
        public virtual void Insert(int index, TreeNode 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)
            {
                owner.AddSorted(node);
                return;
            }

            if (index < 0)
            {
                index = 0;
            }

            if (index > owner.childCount)
            {
                index = owner.childCount;
            }

            owner.InsertNodeAt(index, node);
        }