| | |
Tree View Control
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Jan 2009
Posts: 22
Reputation:
Solved Threads: 0
Hello,
I have a treeview control and want to add a node to it at a desired location or as the child of a Certain Node X.The problem is I will know nodename[or the Text displayed ] of X only at runtime.
How do I Iterate the tree to find the given Node and add a child to it ??
Do I have to write a recursive function that iterates the nodes of a tree,find the given node and add a child to it OR is there an easier way to do this..
I have a treeview control and want to add a node to it at a desired location or as the child of a Certain Node X.The problem is I will know nodename[or the Text displayed ] of X only at runtime.
How do I Iterate the tree to find the given Node and add a child to it ??
Do I have to write a recursive function that iterates the nodes of a tree,find the given node and add a child to it OR is there an easier way to do this..
Based on what information you want to add child nodes?
Can you explain more about why you want to do this, this will help us to provide better solution.
Can you explain more about why you want to do this, this will help us to provide better solution.
Freedom in the Mind, Faith in the words.. Pride in our Souls...
Indian Developer
http://falaque.wordpress.com/
Indian Developer
http://falaque.wordpress.com/
•
•
Join Date: Jul 2009
Posts: 954
Reputation:
Solved Threads: 196
•
•
•
•
Hello,
I have a treeview control and want to add a node to it at a desired location or as the child of a Certain Node X.The problem is I will know nodename[or the Text displayed ] of X only at runtime.
How do I Iterate the tree to find the given Node and add a child to it ??
Do I have to write a recursive function that iterates the nodes of a tree,find the given node and add a child to it OR is there an easier way to do this..
public TreeNode[] Find(string key, bool searchAllChildren);
Then, peruse the returned array for your specific node and Add your new node.
Last edited by DdoubleD; Aug 11th, 2009 at 11:37 am. Reason: spelling
•
•
Join Date: Jan 2009
Posts: 22
Reputation:
Solved Threads: 0
Hai,
@DangerDev
I get a input from the user and based on this input there will be corresponding node in my tree view(Can be at any level inside the treeview),and I will know only its name .Have to find this node and append my child node to it..
Where I add my child Node depends on the user and has to be done at runtime..
Hope this Helps..
@DangerDev
I get a input from the user and based on this input there will be corresponding node in my tree view(Can be at any level inside the treeview),and I will know only its name .Have to find this node and append my child node to it..
Where I add my child Node depends on the user and has to be done at runtime..
Hope this Helps..
•
•
Join Date: Jul 2009
Posts: 954
Reputation:
Solved Threads: 196
It will return a reference to the node collection, so your changes will apply.
•
•
Join Date: Jul 2009
Posts: 954
Reputation:
Solved Threads: 196
•
•
•
•
Hai,
@DangerDev
I get a input from the user and based on this input there will be corresponding node in my tree view(Can be at any level inside the treeview),and I will know only its name .Have to find this node and append my child node to it..
Where I add my child Node depends on the user and has to be done at runtime..
Hope this Helps..
[CODE]
public static TreeNode FindTreeNodeText(TreeNodeCollection nodes, string findText)
{
TreeNode foundNode = null;
for (int i = 0; i < nodes.Count && foundNode == null; i++)
{
if (nodes[i].Text == findText)
{
foundNode = nodes[i];
break;
}
if (nodes[i].Nodes.Count > 0)
foundNode = FindTreeNodeText(nodes[i].Nodes, findText);
}
return foundNode;
}
[\CODE]
The node collection is the TreeView's Nodes (tv.Nodes). If found, you simply foundNode.Add(new TreeNode());
•
•
Join Date: Jul 2009
Posts: 954
Reputation:
Solved Threads: 196
Reposting method: I don't know why the tags didn't display the code properly. If this fixes your problem, please flag as Solved--thanx.
C# Syntax (Toggle Plain Text)
public static TreeNode FindTreeNodeText(TreeNodeCollection nodes, string findText) { TreeNode foundNode = null; for (int i = 0; i < nodes.Count && foundNode == null; i++) { if (nodes[i].Text == findText) { foundNode = nodes[i]; break; } if (nodes[i].Nodes.Count > 0) foundNode = FindTreeNodeText(nodes[i].Nodes, findText); } return foundNode; }
![]() |
Similar Threads
- Tree view designing in window applications? (C#)
- using tree view and then geting thumbnail ....plz help (VB.NET)
- Thumbnail and tree view (VB.NET)
- how to get thumbnail view using tree view (VB.NET)
- Tree view Problem...Plz help (VB.NET)
- Tree View Problem (VB.NET)
- Tree View and Past Back (ASP.NET)
- How to do this tree view information (ASP.NET)
- Calculating a control position on a window (C)
- Tree View (ASP)
Other Threads in the C# Forum
- Previous Thread: Noob question
- Next Thread: How do I move through directories?
| Thread Tools | Search this Thread |
Tag cloud for C#
.net access ado.net algorithm array barchart bitmap box broadcast buttons c# chat check checkbox client color combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees development draganddrop drawing encryption enum event excel file files form format forms function gdi+ image index input install java label list listbox listener login mandelbrot math mouseclick mysql networking object operator oracle path photoshop picturebox pixelinversion post prime programming radians regex remote remoting resource richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml





