471,089 Members | 1,548 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,089 software developers and data experts.

ASP.Net 2.0 Treeview scroll/focus problem

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
May 23 '06 #1
2 9589
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);

"Claus" wrote:
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

Jun 8 '06 #2
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.

"William Sullivan" wrote:
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);

"Claus" wrote:
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

Jun 9 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Dave | last post: by
1 post views Thread by Rasmus | last post: by
1 post views Thread by JC | last post: by
1 post views Thread by mongphong28 | last post: by
3 posts views Thread by =?Utf-8?B?anAybXNmdA==?= | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.