views:

110

answers:

1

I am trying to dynamically populate a treeview object on a sharepoint webpart. For some reason, the node population is triggered automatically and without user input. Below is a sample of how I set up the tree and webpart.

Any suggestions on how to prevent the automatic populate would be appreciated.

The following is in the createchildcontrols method:

                this.Tree = new TreeView();
                this.Tree.EnableClientScript = false;
                this.Tree.PopulateNodesFromClient = true;
                this.Tree.Nodes.Add(this.FetchTreeNode());
                this.Tree.TreeNodePopulate += new TreeNodeEventHandler(Tree_TreeNodePopulate);

The handler looks like this:

void Tree_TreeNodePopulate(object sender, TreeNodeEventArgs e)
    {
       List<MyNode> children = this.FetchChildren(e.Node.Value);
       foreach (MyNode child in children)
       {
           TreeNode node = new TreeNode(child.Name, child.UniqueId, child.IconPath);
           node.PopulateOnDemand = true;
           node.SelectAction = TreeNodeSelectAction.Expand;
           e.Node.ChildNodes.Add(node);
       }
    }

I've been banging my head on this one for a long time, any suggestions would be appreciated.

A: 

So I finally figured this out... for some reason, the default behavior of the treeview was to be expanded, so it would call the treenode populate function right off the bat. I was able to get this to work by calling the treeview.collapseall() method.

tbischel