ASP.Net 2.0 Treeview scroll/focus problem

Discussion in 'ASP .Net' started by Claus, May 23, 2006.

  1. Claus

    Claus Guest

    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
    Claus, May 23, 2006
    #1
    1. Advertising

  2. 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
    >
    =?Utf-8?B?V2lsbGlhbSBTdWxsaXZhbg==?=, Jun 8, 2006
    #2
    1. Advertising

  3. 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
    > >
    =?Utf-8?B?V2lsbGlhbSBTdWxsaXZhbg==?=, Jun 9, 2006
    #3
  4. Claus

    ironste

    Joined:
    Sep 7, 2006
    Messages:
    1
    Location:
    italy
    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!
    ironste, Sep 7, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. nicholas
    Replies:
    0
    Views:
    438
    nicholas
    Dec 7, 2004
  2. Kevin
    Replies:
    1
    Views:
    9,516
    Roland
    Feb 5, 2005
  3. Sathiamoorthy

    Enable Scroll up and scroll down in CR-report

    Sathiamoorthy, Nov 9, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    891
    zobalee
    Nov 28, 2006
  4. UJ
    Replies:
    1
    Views:
    566
    John Timney \(MVP\)
    Nov 1, 2006
  5. Roger
    Replies:
    3
    Views:
    320
Loading...

Share This Page