VisualUIAVerify.Controls.AutomationElementTreeNode.InsertChildNode C# (CSharp) Method

InsertChildNode() private method

This method will insert currentTestTypeRootNode between child nodes of this currentTestTypeRootNode
private InsertChildNode ( TreeNode childNode ) : void
childNode System.Windows.Forms.TreeNode
return void
        internal void InsertChildNode(TreeNode childNode)
        {
            Debug.Assert(childNode.TreeView == null, "childNode.TreeView must be null otherwise it will not be added to children collection");
            //we need to safe
            using (SynchronizationManager.Lock())
            {
                //add this new children to collection
                AddChildrenNodesToTreeNode(new TreeNode[] { childNode }, false, true);

                this._newChildElementInserted = true;
            }
        }

Usage Example

コード例 #1
0
        /// <summary>
        /// This method will select to parent AutomationElement from the currentTestTypeRootNode. If the parent element
        /// is not in a tree then this method will try to find the element and show him in a tree.
        /// </summary>
        public void GoToParentFromNode(AutomationElementTreeNode node)
        {
            CheckNodeIsValid(node);

            TreeNode nodeToSelect = node.TreeNode.Parent;

            if (nodeToSelect == null)
            { //there is no parent to this currentTestTypeRootNode, we should try to find one
                AutomationElement parentElement = this._treeWalker.GetParent(node.AutomationElement);

                if (parentElement == null)
                {
                    return;
                }

                //we create tree currentTestTypeRootNode for the element
                TreeNode newRootNode = TreeHelper.CreateNodeForAutomationElement(parentElement, this);

                //take old root
                TreeNode currentRootNode = this._elementsTreeView.Nodes[0];

                //clear the tree
                this._elementsTreeView.Nodes.Clear();

                //insert it as a new root
                this._elementsTreeView.Nodes.Add(newRootNode);

                AutomationElementTreeNode newRootElementNode = (AutomationElementTreeNode)newRootNode.Tag;
                //insert old root to children collection of new root
                newRootElementNode.InsertChildNode(currentRootNode);

                nodeToSelect = newRootNode;
            }

            _elementsTreeView.SelectedNode = nodeToSelect;
            nodeToSelect.EnsureVisible();

            //expand new root which cause populating of all child elements
            nodeToSelect.Expand();
        }