Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Recursive: See recursive
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
01083365
Message ID:
01083873
Vues:
10
I got a little time to write some test code (kids are watching Aladin).
private void button2_Click(object sender, System.EventArgs e)
{
	TreeNode retVal = this.Caller();
	if (retVal != null)
	{
		MessageBox.Show(retVal.Text);
		retVal.BackColor = Color.PowderBlue;
	}
	else
	{
		MessageBox.Show("Null i.e. da node was not found");
	}
}

private TreeNode Caller()
{
	TreeNode retVal = null;
	foreach (TreeNode n in this.treeView1.Nodes)
	{
		retVal = PrintRecursive(n);
		if (retVal != null)
		{
			break;
		}
	}
	return retVal;
}

private TreeNode PrintRecursive(TreeNode treeNode)
{
	if (treeNode.Text.Trim() == this.textBox3.Text.Trim())
	{
		return treeNode;
	}

	TreeNode retVal = null;
	foreach (TreeNode tn in treeNode.Nodes)
	{
		retVal = PrintRecursive(tn);
		if (retVal != null)
		{
			break;
		}
	}

	return retVal;
}
I like it returning a TreeNode.

I know a lot of you have told me I don't need the eoreach loop in the Caller method and I thought I didn't eaither until I tried not to have it <s>. It turns out I don't have a TreeView I have a ForestView <lol> i.e. I have multiple root nodes. I guess I didn't see the forest for all the trees.

Einar
Semper ubi sub ubi.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform