Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
15
Forcing WebTree to scroll to show selected node.
posted

I'm creating a user control that is a combobox which drops down into a tree.  If the combobox has an initial value, I want to expand the tree to the corresponding selected node, and when the user opens the tree, the tree should be scrolled so that the selected node is visible.

I have a recursive tree opener, which expands the tree down the hierarchy to the desired node, and once reaching it, calls this line:

childNode.Selected = true;

 And it was working fine.  The screen came up, the user clicked on the combobox to open the tree, and the tree was scrolled so that the selected node was visible.

However, I had to make a change because the tree flashed on the screen while it was being built. While the page was coming up, the tree would appear for a split second and then disappear.

 To prevent this, I added these two lines before my tree initialization:

uwtTreeComboBoxTree.Style.Add("display", "none");
uwtTreeComboBoxTree.Style.Add("visibility", "hidden");
InitializeTreeData(Lineage);

Worked great!  The tree no longer appeared while the page was building.

However, now my node selection isn't scrolled into view.  When the user clicks on the combobox, the tree appears, the proper node is selected, but they have to scroll down to see it.

It seems that hiding the tree makes the 'autoscroll to selected node' not work.

Is there any way to get the selected node to be scrolled to by default?

 Thanks,

 Shawn


 

 

  • 15
    posted

    Ok, found a way to get it to work.

    Wrote this javascript function:

    function ScrollToSelectedNode(oTree)
    {
       selectedNode = oTree.getSelectedNode();
       if (selectedNode != null)
          selectedNode.scrollIntoView();
    }

    I call this function each time the user clicks to open the tree, after the tree is displayed.  (Which is slightly funky, but is ok.)