ASP.Net 2.0 Treeview Nodes Not Expanding or Selecting?

Last post 10-01-2009 1:17 AM by boaldave1. 1 replies.

Sort Posts:

  • ASP.Net 2.0 Treeview Nodes Not Expanding or Selecting?

    10-01-2009, 12:51 AM
    • Member
      1 point Member
    • boaldave1
    • Member since 08-14-2009, 8:04 PM
    • Posts 7

    I am adding nodes to a TreeView control in Page Load as follows (code abbreviated):

    foreach (WorkFlowTask workFlowTask in WorkFlowTasks)
    {
       aNode =
    new TreeNode(workFlowTask.TaskName, workFlowTask.OrderOfCompletion.ToString());
       CreateNode(aNode); //This method adds nodes to their relative node path

       //I have tried a couple things to cause a node to be expanded or collapsed here:
       if
    (workFlowTask.IsCurrentTask)
       {
          aNode.Expand(); 
          aNode.Expanded = 
    true;

         
    //and I also had some code to expand Parents:
          // ExpandSelfAndAllParents(aNode);

          //and I also had some code to Select a node (SelectedNodeStyle is set to yellow highlight:
          //aNode.Select(); 
          aNode.Selected = true;
       }
       else
       {
          aNode.Expanded = false;
          aNode.Selected = false;
       }
    }
    if (tvwWorkFlow.SelectedNode != null)
       tvwWorkFlow.SelectedNode.Expand();

     

    The result is the TreeView control renders all nodes expanded and the selected node is not highlighted in yellow (until I click on a node).

    When I check tvwWorkFlow.SelectedNode after the Treeview control is built, it is null. The Selected property of every node in the TreeView, is null.

    Help! Thanks...

     

  • Re: ASP.Net 2.0 Treeview Nodes Not Expanding or Selecting?

    10-01-2009, 1:17 AM
    Answer
    • Member
      1 point Member
    • boaldave1
    • Member since 08-14-2009, 8:04 PM
    • Posts 7

    The answer was simple:

    Move the Expand(), Collapse(), and Select() code to the point after the TreeView has been completely populated as follows:

    foreach (WorkFlowTask workFlowTask in WorkFlowTasks)
    {
       aNode =
    new TreeNode(workFlowTask.TaskName, workFlowTask.OrderOfCompletion.ToString());
       CreateNode(aNode); //This method adds nodes to their relative node path

    }

    // AFTER TREEVIEW IS BUILT:
    foreach (Node o in trvWorkFlow.Nodes)
    {
       
    // INSERT CODE HERE TO SELECTIVELY EXPAND, COLLAPSE, OR SELECT NODES.
       o.Expand();
       o.Collapse();
       o.Select();
    }

     

Page 1 of 1 (2 items)