473,756 Members | 5,595 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 9790
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.WriteBeg inTag("a");
writer.WriteAtt ribute("id", "a" + this.ValuePath) ;
writer.Write(Ht mlTextWriter.Se lfClosingTagEnd );
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(thi s, 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.Re gisterStartupSc ript(this.GetTy pe(),
"scrollTo", "scrollTo(\ "a" + selected.ValueP ath + "\");", 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_Da ta
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_Da ta.selectedNode ID.value;
var selectedNode =
Document.all?Do cument.all[name]:Document.getEl ementById(name) ;
if(selectedNode ){ selectedNode.sc rollIntoView(tr ue); }

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.WriteBeg inTag("a");
writer.WriteAtt ribute("id", "a" + this.ValuePath) ;
writer.Write(Ht mlTextWriter.Se lfClosingTagEnd );
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(thi s, 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.Re gisterStartupSc ript(this.GetTy pe(),
"scrollTo", "scrollTo(\ "a" + selected.ValueP ath + "\");", 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
1825
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
15549
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 listBox1_SelectedIndexChanged(object sender, System.EventArgs e) { string selected; selected = this.listBox1.SelectedItem.ToString(); if(selected == "Error in Supercell 1") {
3
14731
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 know how to use this event, or how to get the scroll bar info? ~Benny
5
3916
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) but only sometimes. Other times it appears behind the parent form and all that is visible is the last few characters of that row. Anyone know what might be causing this and how I can fix it? Thanks.
1
8681
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 able to set the focus to a control. Here's the problem, when you set the focus by using the registerstartupscript method the control gets the focus after the scroll position has been set. When this happens the scroll position
4
6929
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 |__ cover type
1
6367
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 stay on the control, but instead jumps back to the treeview. I'm setting the focus in the AfterSelect event of the treeview, and if I step through the code the desired control does have .Focused = True after I have set it, but then somewhere after...
0
1061
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 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
3
6047
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 TreeView1.ExpandAll(); however, the TreeView control scrolls the last part of the data into focus. How do I either prevent this scrolling or reset the TreeView control's view?
0
9462
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10046
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9722
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6542
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5155
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5318
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3817
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3369
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2677
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.