AddChildren() public method

Add the children nodes of a particular node in the tree. Do this recursively if that parameter is set to true. Also set the node as Checked if is it in the set or chosenObjs.
public AddChildren ( bool recursively, IEnumerable chosenObjs ) : void
recursively bool
chosenObjs IEnumerable
return void
Exemplo n.º 1
0
        /// <summary>
        /// Add the children nodes of a particular node in the tree. Do this recursively if
        /// that parameter is set to true. Also set the node as Checked if is it in the set
        /// or chosenObjs.
        /// </summary>
        public void AddChildren(bool recursively, IEnumerable <ICmObject> chosenObjs)
        {
            // JohnT: if we redo this every time we open, we discard the old nodes AND THEIR VALUES.
            // Thus, collapsing and reopening a tree clears its members! But we do need to check
            // that we have a label node, we put a dummy one in to show that it can be expanded.
            if (Nodes.Count > 0 && Nodes[0] is LabelNode)
            {
                // This already has its nodes, but what about its children if recursive?
                if (!recursively)
                {
                    return;
                }
                foreach (LabelNode node in Nodes)
                {
                    node.AddChildren(true, chosenObjs);
                }
                return;
            }
            Nodes.Clear();             // get rid of the dummy.

            AddSecondaryNodes(this, Nodes, chosenObjs);
            foreach (ObjectLabel label in ((ObjectLabel)Tag).SubItems)
            {
                if (!WantNodeForLabel(label))
                {
                    continue;
                }
                LabelNode node = Create(label, m_stylesheet, m_displayUsage);
                if (chosenObjs != null)
                {
                    node.Checked = chosenObjs.Contains(label.Object);
                }
                Nodes.Add(node);
                AddSecondaryNodes(node, node.Nodes, chosenObjs);
                if (recursively)
                {
                    node.AddChildren(true, chosenObjs);
                }
            }
        }
Exemplo n.º 2
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Finds the node.
		/// </summary>
		/// <param name="searchNode">The search node.</param>
		/// <param name="hvo">The hvo.</param>
		/// <returns></returns>
		/// ------------------------------------------------------------------------------------
		protected LabelNode FindNode(LabelNode searchNode, int hvo)
		{
			//is it me?
			if (searchNode.Label.Hvo == hvo)
				return searchNode;

			//no, so look in my descendants
			searchNode.AddChildren(true, m_rghvoChosen);
			foreach (LabelNode node in searchNode.Nodes)
			{
				LabelNode n = FindNode(node, hvo);
				if (n!=null)
					return n;
			}
			return null;
		}