Hi.
Im having problems updating the Text-attribute of a TreeNode in the TreeView. As far as I understand it node.Text doesnt work at all. To set the node text when populating the Flytree I do this:
FlyTreeNode node = new FlyTreeNode();
node.NodeTypeID = nodeTypeID;
node.Attributes.Add( \"Name\", nodeName );
node.Value = Convert.ToString( nodeValue );
node.ToolTip = nodeTooltip;
if (nodeChilds > 0)
{
FlyTreeNode dummyNode = new FlyTreeNode();
dummyNode.Text = \"Loading...\";
node.ChildNodes.Add( dummyNode );
node.PopulateNodesOnDemand = true;
}
else
node.PopulateNodesOnDemand = false;
node.Expanded = false;
which matches the following declaration in the aspx-page:
'>
.....
This works great and when I do an update on the text for a \"top\"-node this also works great:
FlyTreeNode selectedNode = FlyTreeView.SelectedNode;
int selectedNodeIndex = selectedNode.Index;
int selectedNodeChildrens = selectedNode.ChildNodes.Count;
FlyTreeView.Nodes.Remove( selectedNode );
FlyTreeNode node = new FlyTreeNode();
node.NodeTypeID = nodeTypeID;
node.Attributes.Add( \"Name\", nodeName );
node.Value = Convert.ToString( nodeValue );
if (selectedNodeChildrens > 0)
{
FlyTreeNode dummyNode = new FlyTreeNode();
dummyNode.Text = \"Loading...\";
node.ChildNodes.Add( dummyNode );
}
node.Expanded = false;
FlyTreeView.Nodes.Insert( selectedNodeIndex, node );
But that will not work for nodes one level down or more. So I wrote this (see code below) which in my mind should work, but then I get an error when the page renders - not in my code. So what am I doing wrong? And is this really the correct way to update the node.Text?
Here is the code that doesnt work (its similar to the one above that works except for finding Parent node and using Parent.ChildNodes instead of FlyTreeView.Nodes to remove the old node and adding the new:
int selectedNodeIndex = FlyTreeView.SelectedNode.Index;
int selectedNodeChildrens = FlyTreeView.SelectedNode.ChildNodes.Count;
FlyTreeNode parentNode = FlyTreeView.SelectedNode.Parent;
parentNode.Selected = true;
parentNode.ChildNodes.Remove( FlyTreeView.SelectedNode );
FlyTreeNode node = new FlyTreeNode();
node.NodeTypeID = nodeTypeID;
node.Attributes.Add( \"Name\", nodeName );
node.Value = Convert.ToString( nodeValue );
if (selectedNodeChildrens > 0)
{
FlyTreeNode dummyNode = new FlyTreeNode();
dummyNode.Text = \"Loading...\";
node.ChildNodes.Add( dummyNode );
}
node.Expanded = false;
parentNode.ChildNodes.Insert( selectedNodeIndex, node );
I realize this isnt easy to grasp without having the entire code but its integrated into something bigger and much more complicated so that wont help. Maybe I can get some help anyway.
Any help is very much appreciated!
regards
Henrik