Scroll to SelectedNode

3 posts, 0 answers
  1. Patrick
    Patrick avatar
    2 posts
    Member since:
    Jul 2008

    Posted 20 Jan 2009 Link to this post

    I'm using an example i found on the forum (the one that scrolls to the selected node using a javascript) but it does not work for me.
    My layout is like this:
    i have a databound treeview with checkboxes.
    Under the treeview is a combobox which loads all the nodes that have the checkstatus checked.

    The javascript on my page is:


    <script language="javascript" type="text/javascript"> 

    function ScrollToSelectedNode()



        var treeView = <%=radTreeView1.ClientID %>;

        var selectedNode = treeView.SelectedNode;

        if (selectedNode != null)

        {  document.getElementById(selectedNode.ClientID).scrollIntoView(); }




    When the user selects a node from the combobox this event fires:



    void cmbAllNodes_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)





    string id = e.Value;

    RadTreeNode node = radTreeView1.FindNodeByValue(id);

    node.Selected =







    In the aspx file the combobox looks like this:




    telerik:RadComboBox ID="cmbAllNodes" runat="server" Skin="Outlook" Width="160px" AutoPostBack="True" onselectedindexchanged="cmbAllNodes_SelectedIndexChanged"  onclientselectedindexchanged="ScrollToSelectedNode">

    <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>




    So as you can see, when the selected index is changed the selected node of the treeView is changing but the scroll does not.
    I call the client side method ScrollToSelectedNode when the user has selected a node from the combobox but the treeView does not scroll to it.
    The help is much appreciated.
    Thank you.
    EDIT: I found out that var treeView = <%=radTreeView1.ClientID %>; does not return my instance of the RadTreeView but in fact it returns a DIV. What am i doing wrong?


  2. Veselin Vasilev
    Veselin Vasilev avatar
    2992 posts

    Posted 22 Jan 2009 Link to this post

    Hi Patrick,

    I have already replied to your support ticket:

    Please check this help article:
    How To > Client-Side Programming > Scrolling to a Node when Page first loads

    Note that the TreeView needs to have its Height property set.

    You need to put your code in the pageLoad() event instead of body onload.
    This will guarantee that all the controls are created and initialized on the page.
    You can check this blog post for more information.

    Veselin Vasilev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Patrick
    Patrick avatar
    2 posts
    Member since:
    Jul 2008

    Posted 22 Jan 2009 Link to this post

    The thing that worked for me is here:

    The only thing is that you have to delay the call or just put the script just before the </body> tag.

    Thanks you.
Back to Top