This is a migrated thread and some comments may be shown as answers.

Scroll to SelectedNode

2 Answers 133 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Patrick
Top achievements
Rank 1
Patrick asked on 20 Jan 2009, 04:02 PM
Hello.
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(); }

}

 

</script>

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

protected

 

void cmbAllNodes_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)

 

 

{

 

string id = e.Value;

RadTreeNode node = radTreeView1.FindNodeByValue(id);

node.Selected =

true;

 

 

}

 

 

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>

</telerik:RadComboBox>

 

 

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 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 22 Jan 2009, 09:28 AM
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.
and

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.


Greetings,
Veselin Vasilev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Patrick
Top achievements
Rank 1
answered on 22 Jan 2009, 10:17 AM
The thing that worked for me is here:

http://blogs.telerik.com/dimodimov/posts/08-12-13/Don_t_Use_BODY_ONLOAD_in_ASP_NET_AJAX_Websites.aspx

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

Thanks you.
Tags
TreeView
Asked by
Patrick
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Patrick
Top achievements
Rank 1
Share this question
or