Expand the tree to a specified RadTreeItem

6 posts, 0 answers
  1. Julien
    Julien avatar
    236 posts
    Member since:
    Jul 2010

    Posted 27 Aug 2010 Link to this post

    Hi!

    How can I programatically expand a Tree to a specified RadTreeItem?

    I've an ItemPrepared method that select it, and I want to open all part of my tree to get my element visible:

    private void RadTreeViewItemPrepared(object sender, Telerik.Windows.Controls.RadTreeViewItemPreparedEventArgs e)
    {
        e.PreparedItem.IsSelected = true;
        //Do something on _uxRadTreeView to display my e.PreparedItem displayec
    }
  2. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1511 posts

    Posted 01 Sep 2010 Link to this post

    Hi Julien,

    Try calling the BringIntoView() method of the prepared item. Also, please have a look at our help articles regarding expanding and collapsing TreeViewItems.

    All the best,
    Kiril Stanoev
    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. UI for WPF is Visual Studio 2017 Ready
  4. Julien
    Julien avatar
    236 posts
    Member since:
    Jul 2010

    Posted 16 Sep 2010 Link to this post

    So I tried, but it seems that the RadTreeViewItemPrepared event is throwed only when we expand a window, and not when we add an object to the collection.

    I saw the ExpandItemByPath method, I don't know which field is used in the path? I'm using template selector and all my level have images in its data template.

    And, How is it managed when we have two element with the same name?

    Thank you
  5. Hristo
    Admin
    Hristo avatar
    352 posts

    Posted 20 Sep 2010 Link to this post

    Hello Julien,

    ItemPrepared event is fired when the item container is created and ready for use. Which is just about before displaying the item. So the event may not be fired when item is added to the collection.

    You can check the example for "Programatic Expand" in "Controls\NAVIGATION\TreeView" section under the following link http://demos.telerik.com/wpf/. It represents an alternative way in which a particular item can be expanded. The example uses data bound tree view.

    If your tree is data bound then you can customize which field from your data will be used by the ExpandItemByPath function. This can be done via TextSearch.Text  attached property of the tree view. Following code snippet shows how you can set the ExpandItemByPath to use the Name property of the Entity business object.

    <HierarchicalDataTemplate x:Key="EntityTemplate" ItemsSource="{Binding Children}">
        <TextBlock Text="{Binding Name}" />
    </HierarchicalDataTemplate>
    ...
    <telerik:RadTreeView Name="SampleTreeView" ItemsSource="{Binding .}"
            ItemTemplate="{StaticResource EntityTemplate}"
            telerik:TextSearch.TextPath="Name" />

    If your tree view is not data bound, then you can try expanding the parent item containers all the way from root to your desired item. This approach hides many difficulties because the item containers may not be created when you need them.

    Hope this helps. Please let us know if you need more help.


    Sincerely yours,
    Hristo Milyakov
    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
  6. Julien
    Julien avatar
    236 posts
    Member since:
    Jul 2010

    Posted 21 Sep 2010 Link to this post

    Several remarks:

    -My recursive tree isn't data bound
    -My root node doesn't know in which subnodes is contained my seed
  7. Hristo
    Admin
    Hristo avatar
    352 posts

    Posted 24 Sep 2010 Link to this post

    Hi Julien,

    When your tree is not data bound you can use the ExpandItembyPath function and pass it a path parameter. The path must be composed of strings from the Header property of RadTreeViewItem separated by a "\". No need to use TextSearch.TextPath property. When having items with duplicated name the first one is expanded. I've attached a sample project demonstrating the approach. It's purpose it to clarify the explanations above and not to be a best practice or thorough implementation.

    Regarding your second remark: if I got you right - you don't know the whole path to the item you want to Expand. If so, you must provide some mechanism to retrieve the full path and then use it when expanding the item. You can store the path in structure appropriate to you while creating the tree (for example inside the item Tag property).

    Finally you can take a look at the following article for more info about how to expand particular item and show it : http://www.telerik.com/support/kb/silverlight/treeview/expanding-databound-treeview-on-initial-load.aspx

    Best wishes,
    Hristo Milyakov
    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
Back to Top
UI for WPF is Visual Studio 2017 Ready