Programmatically scroll a RadTreeView

5 posts, 0 answers
  1. Trevor
    Trevor avatar
    2 posts
    Member since:
    Nov 2010

    Posted 23 Nov 2010 Link to this post

    Hi,

    I've been trying to enable code-initiated scrolling in a RadTreeView object. The idea is that after a new item is added to the RadTreeView, the component scrolls to this new component so a user may edit the items name. I've tried:

    RadTreeViewItem.BringIntoView()
    RadTreeView.ScrollView.ScrollToItem()
    RadTreeView.ScrollView.ScrollToVerticalOffset()

    All have no effect on the contents of the RadTreeView. Scrolling works fine with the mouse. I've also tried wrapping these calls with:

    RadTreeView.UpdateLayout()
    RadTreeView.ScrollViewer.InvalidateScrollInfo()

    which didn't help.

    After reading about ScrollViewer in detail, I tried implementing a separate scrollview to contain the RadTreeView, but that didn't work very well.

    How can I scroll via code?


    Thanks,
    Trevor

    Silverlight version: 4.0
    OS: Windows 7 64bit
    Browser: Internet Explorer 8.0.7600.16385
    Telerik Component: RadTreeView, Telerik.Windows.Controls.Navigatino.dll v2.0.50727
    Language: C#

    To Reproduce Behaviour:
    -Create a RadTreeView with some entries
    -Make browser window smaller, so that scrollbars appear
    -Ensure scrolling works with mouse and mouse wheel
    -Put button/code to call RadTreeView.* methods that are supposed to scroll contents

  2. Hristo
    Admin
    Hristo avatar
    352 posts

    Posted 26 Nov 2010 Link to this post

    Hello Trevor,

    I've created a sample application. Can you please take a look at it and see if it fits to your case. I would like to suggest you not to use a programmatical scrolling and not trying to command the tree view scroll because the scrolling logic inside the tree view is rather complex and is not designed for direct programmatical use. 

    If you want to manipulate the visual representation of the tree view it's better to use BringIntoView method along with ExpandItemByPath and GetItemByPath. You can get more info about these method in our online help:
    http://www.telerik.com/help/silverlight/radtreeview-features-treeviewitem-bring-into-view-support.html
    http://www.telerik.com/help/silverlight/radtreeview-feautres-treeviewitem-expanding-and-collapsing-items.html
    http://www.telerik.com/help/silverlight/radtreeview-how-to-get-item-by-path.html

    Also, I was not able to find ScrollToItem() method of the RadTreeView.ScrollViewer. Please correct me if I've missed something.

    Hope this help. Please let us know if you need more info about our controls.

    Kind regards,
    Hristo
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for Silverlight
  3. DevCraft banner
  4. Hristo
    Admin
    Hristo avatar
    352 posts

    Posted 26 Nov 2010 Link to this post

    Hello Trevor,

    I've created a sample application. Can you please take a look at it and see if it fits to your case. I would like to suggest you not to use a programmatical scrolling and not trying to command the tree view scroll because the scrolling logic inside the tree view is rather complex and is not designed for direct programmatical use. 

    If you want to manipulate the visual representation of the tree view it's better to use BringIntoView method along with ExpandItemByPath and GetItemByPath. You can get more info about these method in our online help:
    http://www.telerik.com/help/silverlight/radtreeview-features-treeviewitem-bring-into-view-support.html
    http://www.telerik.com/help/silverlight/radtreeview-feautres-treeviewitem-expanding-and-collapsing-items.html
    http://www.telerik.com/help/silverlight/radtreeview-how-to-get-item-by-path.html

    Also, I was not able to find ScrollToItem() method of the RadTreeView.ScrollViewer. Please correct me if I've missed something.

    Hope this help. Please let us know if you need more info about our controls.

    Kind regards,
    Hristo
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for Silverlight
  5. Trevor
    Trevor avatar
    2 posts
    Member since:
    Nov 2010

    Posted 26 Nov 2010 Link to this post

    Hi Hristo,

    I downloaded the posted sample project and it works for me. So,I tried using in my own project BringIntoView() with no luck. Here is the code fragment:
    var treeViewItem = treeView.ContainerFromItemRecursive(newNode);
    treeViewItem.ExpandAll();
    treeViewItem.BringIntoView();
    treeViewItem.BeginEdit();

    I'm very certain the treeViewItem is valid, because .BeginEdit() works properly. I then tried to more closely match the sample project posted, however getting the container by text path wouldn't work. 

    On the support page for Bring Into View, I noticed that there are two conditions that need to be fullfilled:
    • They work only for immediate items.
    • They will not work before the item containers have been generated.
    What is an immediate item, and when are the item containers generated?

    Thanks,

    Trevor

  6. Hristo
    Admin
    Hristo avatar
    352 posts

    Posted 01 Dec 2010 Link to this post

    Hi Trevor,

    Are you setting the TextSearch.TextPath attached property to the tree view? I'm doing this in the xaml.

    The bring into view should work fine if the item container is created. So, can you please check and see if this is the reason for the issue.

    Kind regards,
    Hristo
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for Silverlight
Back to Top
DevCraft banner