ASP.Net 2.0 Treeview scroll/focus problem

C

Claus

Hello,

I have a long treeview with scrollbars. When I scroll down and press a treeview node, then the Load event fires and navigate in an iframe to another page. The problem is, that afterwards the treeview is collapsed and the node isn't selected. Expanding and selecting the node via code in the load event works, but how do I achieve, that the treeview scrolls down to the selected node?

Thanks for any help
Claus
 
G

Guest

I just accomplished this. Believe me, it isn't easy. You have to:
Create a class that extends from TreeNode and override the RenderPreText
method
In this method, add code to insert a new anchor tag with an identifiable id
a la
writer.WriteBeginTag("a");
writer.WriteAttribute("id", "a" + this.ValuePath);
writer.Write(HtmlTextWriter.SelfClosingTagEnd);
Create a class that extends from TreeView and override the CreateNode method
In this method, add code that returns an instance of your new TreeNode class
(here called AdvTreeNode)
protected override TreeNode CreateNode()
{
return new AdvTreeNode(this, false);
}
Having done this, you can now create a javascript method (let's call it
scrollTo) that will scroll to this anchor tag: "scrollTo('a" + node.ValuePath
+ "');"
You can register this as a client startup script at the page level by using:
ClientScript.RegisterStartupScript(this.GetType(),
"scrollTo", "scrollTo(\"a" + selected.ValuePath + "\");", true);
 
G

Guest

I just discovered that it's extremely easy to get the id of the currently
selected node and then scroll to it.

The TreeView creates an object in Javascript on the client side that's called
[treeview name]_Data
i.e., if the treeview is named tvNavigation, the object's name would be
tvNavigation_Data
This object has a property called selectedNodeID. This property has a ...
property called value that contains the id of the currently selected node. So

var name = tvNavigation_Data.selectedNodeID.value;
var selectedNode =
Document.all?Document.all[name]:Document.getElementById(name);
if(selectedNode){ selectedNode.scrollIntoView(true); }

will scroll the currently selected node into view.
 
Joined
Sep 7, 2006
Messages
1
Reaction score
0
This works!

Thanks a lot =?Utf-8?B?V2lsbGlhbSBTdWxsaXZhbg==?= !!
I just subscribed this forum to say a BIG THANK to your solution! (very simple indeed!)
Bye!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,222
Members
46,810
Latest member
Kassie0918

Latest Threads

Top