Home - Forums-.NET - FlyTreeView (ASP.NET) - Syntax Question

FlyTreeView (ASP.NET)

Technical support and KB related to the FlyTreeView control

This forum related to following products: FlyTreeView for ASP.NET

Syntax Question
Link Posted: 30-Aug-2006 03:24
Hello,

I am having some difficulty adding child nodes to parent nodes.  Here is what I'm doing...

I add parent nodes for each record in a table (This works, I can see these in the tree.)

ftvLEVEL1TREE = New NineRays.WebControls.FlyTreeNode
ftvLEVEL1TREE.Text = myQRY(\"NAME\").ToString
ftvLEVEL1TREE.Value = myQRY(\"DEPARTMENT\").ToString
ftvDEPARTMENT.Nodes.Add(ftvLEVEL1TREE)

However, when I can't figure out how to find a node by value and add to it.  So lets say, I know the Value of a Node is \"17\" how can I find and add a child node to it?

I've tried...

ftvDEPARTMENT.Nodes.FindByValue(\"17\"), True).Add(ftvLEVEL2TREE)

As well as...

ftvDEPARTMENT.FindByValue(\"17\").Add(ftvLEVEL2TREE)

Neither of those works, which is probably normal since I'm unclear on the proper syntax.  Can someone help me out?

Thank You
Kevin
Link Posted: 30-Aug-2006 03:49
WARNING: I DO NOT WORK FOR 9RAYS!!!!

Is the \"FindNodesByValue\" function working?

Assuming that's the case:
I see a potential problem, though I'm no expert.
Both of the lines are adding nodes to a node object:

ftvDEPARTMENT.FindByValue(\"17\").Add(ftvLEVEL2TREE)

and

ftvDEPARTMENT.Nodes.FindByValue(\"17\"), True).Add(ftvLEVEL2TREE)

Each node object contains it's own set of nodes and that is what needs to be added to.

so, try...

ftvDEPARTMENT.Nodes.FindByValue(\"17\"), True).Nodes.Add(ftvLEVEL2TREE)

or

ftvDEPARTMENT.FindByValue(\"17\").Nodes.Add(ftvLEVEL2TREE)
Link Posted: 30-Aug-2006 04:29
Thanks for your help Tazbill.  Unfortunately, no luck yet.  

ftvDEPARTMENT.Nodes.FindByValue(\"17\"), True).Add(ftvLEVEL2TREE)

This line you provided is a duplicate of the line I had.  It doesn't error out, but doesn't do anything either.  I'm assuming it can't find the value, but the value is definitly assigned to a parent node.  As when the document appears, the parent nodes are there, but the child node is not.

If I do this...

ftvDEPARTMENT.Nodes.Add(ftvLEVEL2TREE)

It will add the nodes to the root.  But I just can't seem to figure out how to add the ChildNode to the Parent Node.

For instance, if I use the normal ASP.NET 2.0 TreeView Control and add to it, I can do this...

tvwDEPARTMENT.FindNode(\"12\").ChildNodes.Add(ftvLEVEL2TREE)

And that works.  But CHILDNODES is not a member of FlyTreeNodeCollection.  I'm stumped.  I feel like I'm missing something fundamental here in order to simply add a childnode to a parent node.  I appreciate any help you can give me.

Kevin
Link Posted: 30-Aug-2006 04:41
In C#, the FlyTreeView node objects each have a ChildNodes object in them.

That's what I'm using to dynamically load my tree. Are you adding your nodes client-side or server-side?
Link Posted: 30-Aug-2006 04:48
I believe I'm adding them server-side.  Meaning, it is all happening in the code-behind before the control is rendered/displayed.  I'm not adding anything dynamically after that.

  I'm guessing here, but I think FindByValue returns a Collection, rather than an individual Node.  So this is why I can't attach ChildNodes to it.  Only if I were to enumerate through the results of the FindByValue.  Does that make sense?  I find that odd, as I would have thought FindByValue would return the only instance (In this case \"17\" is unique)

  Or maybe I did something wrong somewhere, does FindByValue return a collection in C#?  And/Or am I barking up the wrong tree, and this isn't the problem?

Kevin
Link Posted: 30-Aug-2006 04:59
Ok...

Here's what I did...

FlyTreeNodeCollection col = ftvTEST.Nodes[0].ChildNodes.FindByValue(\"17\");
col[0].ChildNodes.Add( new FlyTreeNode( \"test\" ) );


Worked.

If you are pulling back a set of departments whose department number will be 17, will there be more than one?

If so, I don't know how to tell the difference.

You may want to add the new node to each of the children.


FlyTreeNodeCollection col = ftvTEST.Nodes[0].ChildNodes.FindByValue(\"17\");

FlyTreeNode newNode = new FlyTreeNode();
newNode.Text = \"Shirt\"; // add an item.
newNode.Value = \"0009893829382\"; // add sku or upc or whatever

foreach( FlyTreeNode node in col )
{
    node.ChildNodes.Add( newNode );
}


But if you're sure you'll only be returning one node with the 'FindByValue' method, you can use the first example.
Link Posted: 31-Aug-2006 15:39
ftvLEVEL1TREE = New NineRays.WebControls.FlyTreeNode
ftvLEVEL1TREE.Text = myQRY(\"NAME\").ToString
ftvLEVEL1TREE.Value = myQRY(\"DEPARTMENT\").ToString
ftvDEPARTMENT.Nodes.Add(ftvLEVEL1TREE)  


The line ftvDEPARTMENT.FindByValue(\"17\").Add(ftvLEVEL2TREE)  just adds ftvLEVEL2TREE to the search result collection nothing more.

Kevin, probably you should use the following code:


ftvLEVEL1TREE.ChildNodes.Add(ftvLEVEL2TREE);