473,398 Members | 2,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 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 9762
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Dave | last post by:
I use the treeview to open a new form but the treeview reclaims focus after MouseUp. Any solutions to this problem?
1
by: Rasmus | last post by:
I need to grab focus to a specific node i my treeview when I click on my listbox. Here's the code that differs between the different event i the listBox: private void...
3
by: Benny Raymond | last post by:
I've looked around msdn for about an hour now and can't figure out how to place an event when the user scrolls, or even how to get the value of where the scroll bar is actually placed... Anyone...
5
by: rh | last post by:
I created a user control that is made up of a TreeView and a VScrollBar. I set the TreeView.FullRowSelect = True and it works as expected (full row is visible, appears on top of everything else)...
1
by: JC | last post by:
I'm sure you've all seen the save scroll position from 4 guys from rolla which can be found here > http://aspnet.4guysfromrolla.com/articles/111704-1.aspx BUT try to get that to work AND still be...
4
by: praveen | last post by:
I have a form with treeview control loaded from xml document,text box, two buttons named "Find" and "FindNext" and my treeview which looks like below. Details |__ policy status |__ created by...
1
by: mongphong28 | last post by:
Hi, I'm using a treeview as a menu, and when the user clicks on a node I want the focus to set to a control (ie textbox) in a panel to the right. The problem I'm having is the focus will not...
0
by: Claus | last post by:
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...
3
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
I have a TreeView control that I am populating with a lot of data. I have been asked to expand the nodes so management can quickly access the individual elements. This is easy to do with...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.