Programmatically scrolling a treeview.

5 posts, 1 answers
  1. Edvin Brudevoll
    Edvin Brudevoll avatar
    4 posts
    Member since:
    Jul 2012

    Posted 29 Sep 2010 Link to this post

    Hi.

    I am trying to programmatically scrolling a treeview. The code I use is:
     

    double

     

     

    d = myTreeView.ScrollViewer.VerticalOffset;

     

     

    myTreeView.ScrollViewer.ScrollToVerticalOffset(d + 200);

    But nothing happens, no scrolling is performed.
    Am I using the correct methods?
    Should this be done some other way?

    Kind Regards Edvin.

     

     

  2. Answer
    Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 01 Oct 2010 Link to this post

    Hi Edvin Brudevoll,

    From the code snippet you sent, it seems that you are going the right way. Therefore, I cannot tell where the cause for your issue might be.

    However, I prepared a sample project implementing the desired functionality. Please note that I am using a Grid to contain the RadTreeView, because if you put the control inside a StackPanel, the ScrollBar won't be displayed. That`s because the size of the StackPanel is Infinity and it cannot limit the RadTreeView size.

    Please have a look at the project and tell me if it works for you. Do not hesitate to ask if you need further assistance.

    Petar Mladenov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
  4. Edvin Brudevoll
    Edvin Brudevoll avatar
    4 posts
    Member since:
    Jul 2012

    Posted 05 Oct 2010 Link to this post

    Hi again.

    I thing you led me to what is my problem. Your example works fine, and the code we both use seems to be correct.

    At first I thought that my problem was that I keep the treeview inside a stackpanel, and that the visible scrollbar was the scrollbar of another object than the treeview (actually the object hierarchy is: Grid -> StackPanel -> RadPanelBar -> RadPanleBarItem -> RadPanelBarItem -> StackPanel -> StackPanel -> StackPanell -> RadTreeview). But I tested, on the treeview saying that ScrollViewer.HorizontalScrollBarVisibility="Hidden" and ScrollViewer.VerticalScrollBarVisibility="Hidden". This made the scrollbar disappear. I conclude that the object that I try to manipulate is the correct object, the scrollbar is the scrollbar of the treeview.

    I am quite convinced that the problem is: I try to scroll the treeview when the stackpanel in which the treeview is contained is invisible. (I populate the ItemsSource, try to scroll the treeview, and then make the containing stackpanel visible, all of this as the result of clicking a radiobutton).

    1) If I make the stackpanel visible, then invisible, then visible again, the scrolling is performed,
    2) And if I by, in my case some irrelevant piece of code, try to scroll the treeview when the containing stackpanel (and treeview) is visible, the scrolling works fine.

    I conclude that my problem is: scrolling the treeview when the stackpanel in which the treeview is contained, is invisible.

    I will have to try to find a workaround, see whether I can find a way to scroll the treeview after it has become visible. Thanks a lot for your help.

    Kind Regards Edvin.
  5. Edvin Brudevoll
    Edvin Brudevoll avatar
    4 posts
    Member since:
    Jul 2012

    Posted 06 Oct 2010 Link to this post

    Hi once again.

    Think I have understood even more of the problem here.

    Like mentioned in my last post, I populate the ItemsSource bound to the treeview, try to scroll by the code in my first post (and the codde in the zip file) and then make the stackpanel visible. There are quite a few nodes in the treeview. Days ago I concluded that the treeview needs 2 - 3 seconds to draw itself on the screen. This implies that I try to do the scrolling long before the layout and drawing of the treeview is complete, and can not by any means succeed.

    So I conclude that the code for scrolling is correct, but the timing for which I try to do the scrolling is way too early. I try to scroll long before the treeview has drawn itself, seems obvious that this can not be done before after it has drawn itself. This is the problem that I will have to solve.

    Thanks a lot for helpful feedback.

    Kind regards Edvin.
  6. Edvin Brudevoll
    Edvin Brudevoll avatar
    4 posts
    Member since:
    Jul 2012

    Posted 06 Oct 2010 Link to this post

    Hi once again.

    I have tried the following:

    1) Populate the ItemsSource.
    2) Call UpdateLayout() on the treevew.
    3) Perform scrolling.

    And it works. So the clue was, call UpdateLayout() on the treeview BEFORE doing the scrolling.

    MaxEllent.

    Kind regards Edvin.
Back to Top
DevCraft banner