This is a migrated thread and some comments may be shown as answers.

Expand the tree to a specified RadTreeItem

5 Answers 149 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Julien
Top achievements
Rank 1
Julien asked on 27 Aug 2010, 10:43 AM
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
}

5 Answers, 1 is accepted

Sort by
0
Kiril Stanoev
Telerik team
answered on 01 Sep 2010, 03:03 PM
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
0
Julien
Top achievements
Rank 1
answered on 16 Sep 2010, 10:48 AM
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
0
Hristo
Telerik team
answered on 20 Sep 2010, 01:24 PM
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
0
Julien
Top achievements
Rank 1
answered on 21 Sep 2010, 01:48 PM
Several remarks:

-My recursive tree isn't data bound
-My root node doesn't know in which subnodes is contained my seed
0
Hristo
Telerik team
answered on 24 Sep 2010, 09:50 AM
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
Tags
TreeView
Asked by
Julien
Top achievements
Rank 1
Answers by
Kiril Stanoev
Telerik team
Julien
Top achievements
Rank 1
Hristo
Telerik team
Share this question
or