This is supposed to search for a node in a huge Treeview. The node could be found in many places. In other words there may be many nodes and the resulting tree should be expanded depending on where nodes are found.
I was asked to avoid recursivity in this method. The only solution I was able to get is using LINQ queries but I cannot since we are under 2.0 framework.
Can I avoid recursivity in this method?
private void CheckFoundTreeNode(TreeNode startingTreeNode, List<Item> parentItems, ItemNode foundItemNode)
{
foreach (TreeNode childTreeNode in startingTreeNode.Nodes)
{
ItemNode itemNode = TreeBuilder.GetItemNode(childTreeNode);
Item item = itemNode.Item;
bool isParent;
if (item.Ancestor == null)
isParent = parentItems.Contains(item);
else
{
Item ancestor = ((Grammar)item).DirectAncestor;
isParent = parentItems.Contains(ancestor);
}
if (isParent)
{
childTreeNode.Expand();
CheckFoundTreeNode(childTreeNode, parentItems, foundItemNode);
}
else if (itemNode == foundItemNode)
{
startingTreeNode.Expand();
m_ListOfFoundNodes.Add(childTreeNode);
}
}
}
TreeNode
seems to be aSystem.Web.UI.WebControls.TreeNode
, but what areItemNode
andTreeBuilder
, and how are they related? Where do the inputs to this function come from? \$\endgroup\$TreeNode
can also come from theSystem.Windows.Forms
namespace. But indeed, theItemNode
andTreeBuilder
are a bit obscure. \$\endgroup\$