469,636 Members | 1,619 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,636 developers. It's quick & easy.

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

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
0 12580

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Michael Hill | last post: by
2 posts views Thread by Raed Sawalha | last post: by
7 posts views Thread by Yongsub Eric Shin | last post: by
13 posts views Thread by Steve Edwards | last post: by
9 posts views Thread by anunaygupta | last post: by
1 post views Thread by prasiddha | last post: by
5 posts views Thread by Johny | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.