Open.Core.TreeNode.InsertChild C# (CSharp) Method

InsertChild() public method

public InsertChild ( int index, ITreeNode node ) : void
index int
node ITreeNode
return void
        public void InsertChild(int index, ITreeNode node)
        {
            // Setup initial conditions.
            if (node == null) return;
            if (Contains(node)) return; // Ignore if the node has already been added.
            if (index < 0) index = ChildCount;

            // Fire pre-event.
            TreeNodeEventArgs args = new TreeNodeEventArgs(node, index);
            FireAddingChild(args);

            // Store the node.
            ChildList.Insert(index, node);

            // Wire up events.
            node.SelectionChanged += OnChildSelectionChanged;

            // Ensure the parent node is set to this.
            if (node.Parent != this) SetParent(node, this);

            // Fire post-event.
            FireChildAdded(args);
        }