Treeview ExpandItemByPath() not Getting Expanded

5 posts, 0 answers
  1. Chandu
    Chandu avatar
    23 posts
    Member since:
    Jul 2012

    Posted 22 Oct 2012 Link to this post

    Hello All,

    I am working on Telerik RadTreeView to bind all Folders with in Attachment Folder in System HardDrive(D:\\Attachment).
    Am using WCF Service for it and i can able to bind all Folders to TreeView successfully.

    Here my Problem is i have a Button,when i click on that button i need to Expand the tree by its path for that am using
     ExpandItemByPath()
    but am unable to Expand the tree,i have tried it in many ways to solve this issue.

    I enclosed a jpg image for more information.Please find the attachment.

    Any help would be appreciated a lot

    Thanks,
    chandu

  2. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 25 Oct 2012 Link to this post

    Hello Chandu,

    I'm not sure what path you're trying to expand. If you need to expand the entire RadTreeView and all its items, you can use the RadTreeView.ExpandAll() method. If you need to expand the path to a particular item, then you can use the ExpandItemByPath() method. However, you need to keep in mind that in order to take advantage of either of these methods, the RadTreeView has to be fully loaded and initialized.

    This means that if you're using virtualizaiton, these methods won't work properly as a virtualized RadTreeView generates only those RadTreeViewItems that are inside the current viewport. So if you try to expand an item outside the viewport, the ExpandAll() and ExpandItemByPath() methods won't work. If this is your case, it might be better to use the BringPathIntoView() method as demonstrated in this tutorial.

    I hope this information will help you get over the described issue. But if it doesn't, it would greatly help us to send a sample solution demonstrating your approach so that we can take a closer look at it and the issue.

    Kind regards,
    Tina Stancheva
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
  4. Chandu
    Chandu avatar
    23 posts
    Member since:
    Jul 2012

    Posted 25 Oct 2012 Link to this post

    Hello Tina,

    Thanks a lot for the reply.But am still not able to get over the issue.
    In my first post i told that am binding my local System Drive Folders to RadTreeView ,that am doing in page load through the
    WCF Service.
    In button click am trying to expand the tree by its path.
    I have used the same method to expand tree...ExpandItemByPath()

    You can approach my issue from the sample solution through the link given below.
    https://www.dropbox.com/sh/1h59gswo3frcg6f/5ViaRS6FNw

    Thanks
    Chandu
  5. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 29 Oct 2012 Link to this post

    Hello Chandu,

    Thank you for sending over the sample solution. We managed to find the cause for the issue in your solution - it is in the PathSeparator in the RadTreeView control. As you're displaying folders, there is a mix up with the RadTreeView.PathSeparator and the folders structure path separator. In order to avoid such issues, it's better to use a different PathSeparator in the RadTreeView control - for example '|'. Then if you define the path to the items using this separator, the control won't be confused by the path separator in the folders like in the first node - D:\Attachments.

    Also, in order to take advantage of the ExpandItemByPath() method, you need to define which property from the business model should serve as a path segment. As you're building the path using the name of each node, you need to set the TextSearch.TextPath attached property to Name.

    Basically the RadTreeView definition should be updated like this:
    <telerik:RadTreeView x:Name="tree"
               Width="350"
               Height="999"
               ItemsSource="{Binding Children}"
               ItemTemplate="{StaticResource itemTemplateAllLevels}"
               PathSeparator="|"
               telerik:TextSearch.TextPath="Name" />

    And your code-behind logic should look like this:
    private void btnExpand_Click(object sender, RoutedEventArgs e)
    {
        string path = @"D:\Attachments|New folder";  //my physical Folder Path
        tree.ExpandItemByPath(path);
        //tree.BringPathIntoView(path);           
    }

    I modified your solution to demonstrate these changes so please give it a try and let me know if you have more questions.

    Regards,
    Tina Stancheva
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  6. Chandu
    Chandu avatar
    23 posts
    Member since:
    Jul 2012

    Posted 01 Nov 2012 Link to this post

    Hello Tina,

    I tried the sample it is working perfect....Superb

    Thanks a lot.....................


    Regards,
    Chandu
Back to Top
DevCraft banner