By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,926 Members | 1,833 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,926 IT Pros & Developers. It's quick & easy.

How to find node in TreeView by using string(the same as Node.Text) ?

P: n/a
Hi all,

I want to use sting(the same as Node.Text) to judge if a node exists
in TreeView.
I've tried several ways, but seems all failed.

could anybody help me?

Thanks in advance.
//My TreeView is defined to has depth =3 only.
//My code snippet as follows:
// path ="rootNode: parentNode: childNode" // path is something like
this
//try to use the path we already have to judge if a node already
exists in treeveiw

TreeNode rootNode = new TreeNode();
TreeNode parentNode = new TreeNode();
TreeNode childNode = new TreeNode();
for(int depth = 0 ; depth < path.Length -1; depth+
+)
{
string nodeOfTreeView = path[depth]; //to get the
rootNode, if depth ==0
if ( nodeOfTreeView != null) //to prevent some path
only has depth =2 or 1
{
if (depth == 0) //deal with rootNode
{
rootNode.Text = nodeOfTreeView;
rootNode.Value = nodeOfTreeView;
rootNode.NavigateUrl = @"./
ShowComponentDetails.aspx?Name=" + nodeOfTreeView;
if
(TreeViewOfPath.FindNode(rootNode.ValuePath) != null) //is this
corrent??
{
// Indicate that the node was found.
showMsg("The specified node (" +
rootNode.ValuePath + ") was found.");
}
else
{
// Indicate that the node is not in the
TreeView control.
showMsg("The specified node (" +
nodeOfTreeView + ") is not in this TreeView control.");
showMsg("new rootNode =" +
rootNode.Value);

TreeViewOfPath.Nodes.Add(rootNode);
}
}
else if (depth == 1)
{
parentNode.Text = nodeOfTreeView;
parentNode.Value = nodeOfTreeView;
parentNode.NavigateUrl = @"./
ShowComponentDetails.aspx?Name=" + parentNode;

if (isNodeExistInTreeView(parentNode.Text))
{
// Indicate that the node was found.
showMsg("The specified node (" +
parentNode.ValuePath + ") was found.");
}
else
{
// Indicate that the node is not in the
TreeView control.
showMsg("The specified node (" +
nodeOfTreeView + ") is not in this TreeView control.");
showMsg(" rootNode =" + rootNode.Text);
showMsg("new parentNode =" +
parentNode.Value);

rootNode.ChildNodes.Add(parentNode);
}

}
else if(depth == 2)
{
childNode.Text = nodeOfTreeView;
childNode.Value = nodeOfTreeView;
childNode.NavigateUrl = @"./
ShowComponentDetails.aspx?Name=" + childNode;
if (isNodeExistInTreeView(childNode.Text))
{
// Indicate that the node was found.
showMsg("The specified node (" +
childNode.ValuePath + ") was found.");
}
else
{
// Indicate that the node is not in the
TreeView control.
showMsg("The specified node (" +
nodeOfTreeView + ") is not in this TreeView control.");
showMsg(" parentNode =" +
parentNode.Text);
showMsg("new childNode =" +
childNode.Text);

parentNode.ChildNodes.Add(childNode);
}
}
}
//add the treeview we generated to page's form1

Page.FindControl("Form1").Controls.Add(TreeViewOfP ath);
}
*/

Apr 27 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.