views:

20

answers:

0

I'm looking for a way to be able to insert childnodes in to TreeNodes of a Treeview, no matter how deep or far.

I was thinking of using a Dictionary for this, storing the pointers to each object, allowing me to find them if I need to store childnodes under them.

I'm gonna start working on this, but my starting idea might be all wrong, or it could be done simpler. Is there any way this can be done fast and easy?

EDIT: the problem is that I need to find the parentnode before being able to insert the childnode. And I first need to find that reference.

The only search mechanism I know of is the indexOf function. I've seen something about a path separator, but that doesn't seem to be it.

What I need is to make a function that finds the node and returns the instance, and then a function that adds to that instance. The second function won't be hard, but the first will.

The reference is the problem. I can't hardcode 40 or 50 objects, so that I can keep all the variables that contain the pointers...

Here's a piece of code:

foreach(string s in nameList) {
    NameTree.Nodes[0].ChildNodes.Add(new TreeNode(s));
}

This is the initial Tree. I now need to be able to add childnodes even deeper. The problem being that I first need to find the parent node. Since using the "new TreeNode" way makes me unable to have a reference to the node, I'll have to store it somewhere, right?