public void Populate()
        {
            SuspendLayout();
            Clear();

            if (_automation != null)
            {
                foreach (var annContainer in _automation.Containers)
                {
                    if (annContainer.Children.Count > 0)
                    {
                        PageTreeNode page = new PageTreeNode(annContainer, this);
                        TreeRootNode.ChildNodes.Add(page);
                        page.TreeParentNode = TreeRootNode;

                        foreach (var annObject in annContainer.Children)
                        {
                            if (annObject.Id != AnnObject.SelectObjectId && annObject.Id != AnnObject.None)
                            {
                                AnnObjectTreeNode annNode = new AnnObjectTreeNode(annObject, page, _automation, this);
                                page.ChildNodes.Add(annNode);
                            }
                        }

                        if (page.ChildNodes.Count > 0)
                        {
                            Controls.Add(page);
                        }
                    }
                }
            }
            ResumeLayout();
        }
        public void PopulateContainer(AnnContainer annContainer)
        {
            SuspendLayout();
            List <AutomationTreeNode> pages = TreeRootNode.ChildNodes;
            PageTreeNode insertedPage       = null;
            bool         pageExists         = false;

            if (pages.Count > 0)
            {
                foreach (PageTreeNode page in pages)
                {
                    if (page.AnnContainer.PageNumber == annContainer.PageNumber)// page already exists
                    {
                        pageExists = true;
                        RemoveChildsFromTree(page.ChildNodes);
                        page.ChildNodes.Clear();
                        if (annContainer.Children.Count > 0)
                        {
                            foreach (AnnObject annObject in annContainer.Children)
                            {
                                if (annObject.Id != AnnObject.SelectObjectId && annObject.Id != AnnObject.None)
                                {
                                    AnnObjectTreeNode annNode = new AnnObjectTreeNode(annObject, page, _automation, this);
                                    page.ChildNodes.Add(annNode);
                                }
                            }

                            if (page.ChildNodes.Count > 0 && !Controls.Contains(page))
                            {
                                Controls.Add(page);
                            }

                            if (page.IsExpanded)
                            {
                                int startingIndex = Controls.IndexOf(page);
                                AddChildsToTree(page.ChildNodes, ref startingIndex);
                            }
                        }
                        else //Empty Page
                        {
                            pages.Remove(page);
                            Controls.Remove(page);
                        }
                        break;
                    }
                    else if (page.AnnContainer.PageNumber > annContainer.PageNumber) // insert new page
                    {
                        pageExists = true;
                        if (annContainer.Children.Count > 0)
                        {
                            insertedPage = new PageTreeNode(annContainer, this);
                            insertedPage.TreeParentNode = TreeRootNode;
                            foreach (AnnObject annObject in annContainer.Children)
                            {
                                if (annObject.Id != AnnObject.SelectObjectId && annObject.Id != AnnObject.None)
                                {
                                    AnnObjectTreeNode annNode = new AnnObjectTreeNode(annObject, insertedPage, _automation, this);
                                    insertedPage.ChildNodes.Add(annNode);
                                }
                            }
                            pages.Insert(pages.IndexOf(page), insertedPage);
                            Controls.Add(insertedPage);
                            Controls.SetChildIndex(insertedPage, Controls.GetChildIndex(page));
                        }
                        break;
                    }
                }
            }
            if (!pageExists) //add new page
            {
                if (annContainer.Children.Count > 0)
                {
                    PageTreeNode newPage = new PageTreeNode(annContainer, this);
                    newPage.TreeParentNode = TreeRootNode;
                    List <AutomationTreeNode> annNodes = new List <AutomationTreeNode>();
                    foreach (AnnObject annObject in annContainer.Children)
                    {
                        if (annObject.Id != AnnObject.SelectObjectId && annObject.Id != AnnObject.None)
                        {
                            AnnObjectTreeNode annNode = new AnnObjectTreeNode(annObject, newPage, _automation, this);
                            annNodes.Add(annNode);
                        }
                    }
                    newPage.ChildNodes = annNodes;
                    pages.Add(newPage);
                    Controls.Add(newPage);
                }
            }
            ResumeLayout();

            UpdateSelection();
        }