Ejemplo n.º 1
0
        private void GenerateTree(IDialogNodeElement elemenetToExpandOn = null)
        {
            if (elemenetToExpandOn == null)
            {
                var selectedItem = treeDialog.SelectedNode;

                if (selectedItem == null)
                    elemenetToExpandOn = _rootDialogNode;
                else
                    elemenetToExpandOn = (IDialogNodeElement)selectedItem.Tag;
            }

            treeDialog.Nodes.Clear();

            var root = CreateTreeNodeFromDialogNode(_rootDialogNode);
            treeDialog.Nodes.Add(root);

            // Using a recursive approach, we'll generate our tree in the best way we can
            RecurisveAdd(root, _rootDialogNode);

            // Perform a deep search for the node
            var select = FindTreeNodeWithElement(elemenetToExpandOn, root);

            // Expand all and select it
            if (select != null)
            {
                treeDialog.SelectedNode = select;
                select.ExpandAll();
            }
        }
Ejemplo n.º 2
0
        private TreeNode FindTreeNodeWithElement(IDialogNodeElement elementToFind, TreeNode currentNode)
        {
            if (currentNode.Tag == elementToFind)
                return currentNode;

            var dialogNode = currentNode.Tag as DialogNode;

            for (int index = 0; index < dialogNode.Links.Count; index++)
            {
                var link = dialogNode.Links[index];

                if (link == elementToFind)
                    return currentNode.Nodes[index].Nodes[0];

                TreeNode result;

                if (link.NextNode != null)
                {
                    result = FindTreeNodeWithElement(elementToFind, currentNode.Nodes[index].Nodes[0]);

                    if (result != null)
                        return result;
                }
            }

            return null;
        }