CreateNodeForAutomationElement() public static method

Creates TreeNode for the AutomationElement
public static CreateNodeForAutomationElement ( AutomationElement element, AutomationElementTreeControl parentControl ) : TreeNode
element System.Windows.Automation.AutomationElement
parentControl AutomationElementTreeControl
return System.Windows.Forms.TreeNode
        /// <summary>
        /// This method initiliazes all required classes and builds a tree from the root element.
        /// </summary>
        private void InitializeElementTree()
        {
            InitializeTreeWalker();
            //            InitializeTreeBuilder();

            _elementsTreeView.Nodes.Clear();

            if (this._rootElement != null)
            {
                TreeNode rootNode = TreeHelper.CreateNodeForAutomationElement(this._rootElement, this);
                _elementsTreeView.Nodes.Add(rootNode);

                //populate children for root element
                ((AutomationElementTreeNode)rootNode.Tag).EnsureChildrenNodesPopulated(true);
            }
        }
        /// <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();
        }
 /// <summary>
 /// This is only a helper function to create TreeNode to AutomationElement.
 /// </summary>
 private TreeNode CreateTreeNodeForAutomationElement(AutomationElement element)
 {
     return(TreeHelper.CreateNodeForAutomationElement(element, this.AutomationElementTreeControl));
 }