473,395 Members | 1,471 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Dynamic TreeNode creation in runtime

What i want to achieve(in runtime):
A root named "Home" with nodes added to it named "A","B","C" and so on til
"Z".
I want these subnodes named accordingly Home_A, Home_B and so on, in the
code so they can be accessed like Home_G.Node.Add("bla bla").

Basicly, i'm trying to make a "Register" where you can add names, they're
sorted and put in the correct node in the tree. The sorting part i've
figured out.. I have added the nodes in runtime, "manually", without using
loops but it looks very shabby and takes up alot of code. The loop i've been
trying to get working looks like this:

My aproach:
**************************
trTest.Nodes.Add("Home");
for(int i=65; i<91; i++)
{
string ch = Convert.ToString(Convert.ToChar(i));
string create = "Home_" + ch;
TreeNode (Convert.ToString(create)) = new TreeNode(ch); //Se note
trTest.Nodes[0].Nodes.Add(create);
}
//Note: Well... Since TreeNode is a class.. the context it's given
//... in isn't valid... any ideas, pointers, suggestions?
***************************
Nov 15 '05 #1
1 4430
Thus spake Ehsan:
My aproach:
**************************
trTest.Nodes.Add("Home");
for(int i=65; i<91; i++)
{
string ch = Convert.ToString(Convert.ToChar(i));
string create = "Home_" + ch;
TreeNode (Convert.ToString(create)) = new TreeNode(ch); //Se note
trTest.Nodes[0].Nodes.Add(create);
}
//Note: Well... Since TreeNode is a class.. the context it's given
//... in isn't valid... any ideas, pointers, suggestions?
***************************


At this point, there's no need to create a variable with a specific
name:

TreeNode parent = trTest.Nodes.Add("Home"), child;
char suffix;

for (int i = 65; i < 91; i++)
{
suffix = (char) i;
child = parent.Nodes.Add("Home_" + suffix);
// do whatever you need to with child
}

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
Nov 15 '05 #2

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

Similar topics

14
by: placid | last post by:
Hi all, i have this struct for a binary tree node typedef struct treenode { char *word; struct treenode *right; struct treenode *left; }TreeNode;
2
by: JC | last post by:
Hello, I'm looking for examples of how to make dynamic creation of code and dynamic execution of the same code. I want to do some code dynamically and then I want to use it to get some results....
9
by: Mark Allison | last post by:
Hi there, I'm still very much a newbie to C#, and would like to derive from TreeNode to extend the TreeNode class. Here's test program: http://www.vkarlsen.no/pastebin/default.asp?id=4090 I...
2
by: charliewest | last post by:
I need to create textboxes in real-time, the actual number of which is determine by a result from a database query. I have been able to create the controls, and then add them to the ASPX page....
2
by: Fabio Cannizzo | last post by:
I execute the following code: myTreeNode.NodeFont = new Font( ... ); However this does not change the Bounds of the TreeNode and as a result the TreeNode's Text does no longer fit and it in...
0
by: Pascal Costanza | last post by:
Dynamic Languages Day @ Vrije Universiteit Brussel ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Monday, February 13, 2006, VUB Campus Etterbeek The VUB (Programming Technology Lab,...
1
by: None | last post by:
Dynamic array creation Hi all... here's a good one for you... I have a situation where I have some bean, and I need to populate an array field in it... here's the problem... I do not know the...
0
by: drop | last post by:
Hi, I'm currently working with the Treeview control in ASP .Net 2.0. The tree is filled dynamically based on data contained in a MySQL Database. Here is the exact behavior I want : 1 - User...
2
by: Ron M. Newman | last post by:
Hi, Just need a little advice. Id like to build *dynamic* context menus for tree nodes. I'm pretty versed in building context menus and attaching them to tree nodes. My question is, what...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.