472,958 Members | 2,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

How do I add a treenode with a key?

I am trying to add nodes with keys to my treeview. I can add general
nodes without problem with:

//create new node
TreeNode newNode = new TreeNode(myIdNumber);

//create children
TreeNode myPersonNode = new TreeNode(myPerson);
TreeNode myAddressNode = new TreeNode(myAddress);

TreeNode[] myNodes = {myPersonNode, myAddressNode};

newNode.Nodes.AddRange(myNodes);

But now I want to interate throught them and stop when I am at a
certain node. I know I can iterate with:

private void PrintRecursive(TreeNode treeNode)
{
// adapted from msdn

//my nodes I'm testing for
if (treeNode.Index == 2 || treeNode.Index == 3)
MessageBox.Show(treeNode.Text);

// Print each node recursively.
foreach (TreeNode tn in treeNode.Nodes)
{

PrintRecursive(tn);
}
}

But using the index seems wrong. I read the docs where I can add a
key and text, but I can't figure out how to use it. I want to create
a node like above and when I add that node I want it to have a key so
I can find it with my recursive function. How can I find the node I
want besides using index? Thank you.
Jul 15 '08 #1
1 7167
On Jul 15, 10:38*pm, jmDesktop <needin4mat...@gmail.comwrote:
I am trying to add nodes with keys to my treeview. *I can add general
nodes without problem with:

* * * * * * //create new node
* * * * * * TreeNode newNode = new TreeNode(myIdNumber);

* * * * * * //create children
* * * * * * TreeNode myPersonNode = new TreeNode(myPerson);
* * * * * * TreeNode myAddressNode = new TreeNode(myAddress);

* * * * * * TreeNode[] myNodes = {myPersonNode, myAddressNode};

* * * * * * newNode.Nodes.AddRange(myNodes);

But now I want to interate throught them and stop when I am at a
certain node. *I know I can iterate with:

* * * * private void PrintRecursive(TreeNode treeNode)
* * * * {
* * * * * * // adapted from msdn

* * * * * * //my nodes I'm testing for
* * * * * * if (treeNode.Index == 2 || treeNode.Index == 3)
* * * * * * * * MessageBox.Show(treeNode.Text);

* * * * * * // Print each node recursively.
* * * * * * foreach (TreeNode tn in treeNode.Nodes)
* * * * * * {

* * * * * * * * PrintRecursive(tn);
* * * * * * }
* * * * }

But using the index seems wrong. *I read the docs where I can add a
key and text, but I can't figure out how to use it. *I want to create
a node like above and when I add that node I want it to have a key so
I can find it with my recursive function. *How can I find the node I
want besides using index? *Thank you.
If you want to associate some custom value with a TreeNode, that's
precisely what TreeNode.Tag is for.
Jul 15 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: scoobydoo | last post by:
Hello, I am trying to implement ICloneable's Clone() function, using Serialization. However, my code causes an exception. I have a class derived from TreeNode called "Node1". In Node1, I...
2
by: Benny Raymond | last post by:
More problems with this... When I run this code, the main form returns an invalid cast exception as it's executing the line "TreeNode n = (TreeNode) this.Nodes;" Does anyone know what would...
0
by: naija naija | last post by:
Hi All, I'm using the TreView Web Control for my MENU. And the Menu is populated from an XML file below. I want a way in which i can manipulate the XML when i want to manage it without having to...
3
by: markaelkins | last post by:
Hi. I am trying to enter a variable in the treenodesrc of a treenode. I am basically trying to send an ID variable into sql to return different records. I've searched everywhere and cannot find the...
2
by: bclegg | last post by:
Hi, When I implement the example code it errors with 'No parameterless constructor defined for this object.' experimenting with dim o as object = mytreenode.clone() gives the same error. The...
0
by: fred | last post by:
I am using the clipboard to copy and paste a TreeNode but the Tag property does not seem to be copied. I use the Tag property for an Object that contains data relating to the TreeNode. The Tag...
3
by: tanya foster | last post by:
Hello, I am re-writing a visual basic .net application(visual studio 2003) in an asp.net application(visual studio 2005). The vb.net application relied on a treeview and hence, treenodes. The...
0
by: divya1949 | last post by:
Create a windows c# application which will Read a xml file and populate nodes in the treeview. 1 On selection of treenode display the child nodes of that node in listview control 2. ...
1
by: AAaron123 | last post by:
If you see this posted twice - sorry. My news reader showed my first post as "No Longer Available" I have the following in a .css file. The treeNodes behave as if they were "a" elements. ...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.