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

Expand items in TreeView with Hierarchical Template

1 Answer 83 Views
This is a migrated thread and some comments may be shown as answers.
Miguel Rios
Top achievements
Rank 1
Miguel Rios asked on 13 Mar 2010, 02:09 AM
Hi to all,

I am actually working in a project that includes a RadTreeView and i have a question about it... I bind the ItemsSource property of the TreeView to a Hierarchical collection previously elaborated, the collection objects have the properties string Nombre, bool IsSelected, obscollection<myObject> Children among others... but those are importants. Now, i use the next Hierarchical Template:

            telerik:ContainerBinding.ContainerBindings="{StaticResource BindingsCollection}" 
            ItemsSource="{Binding Children}">             
            <StackPanel Orientation="Horizontal"
                <CheckBox x:Name="checky" Tag="{Binding Codigo}" Content="{Binding Nombre}"  IsChecked="{Binding IsSelected, Mode=TwoWay}"/> 

and the next BindingCollection:

            <telerik:ContainerBindingCollection x:Name="BindingsCollection"
                <telerik:ContainerBinding PropertyName="IsSelected" Binding="{Binding IsSelected, Mode=TwoWay}" /> 

Now, i was wondering, how could i expand the path to certain object that have the property IsSelected = true at the time the treeview is loaded?

Something like this....

-Object.IsSelected = true;

Also, can i select multiple objects at the same time? And how hard would it be to perform a Search in this hierarchical collection, highlighting and expanding the parent nodes the objects that corresponds to the search parameterS?

I would really appreciate some help with this... hope you have some ideas...


1 Answer, 1 is accepted

Sort by
Tina Stancheva
Telerik team
answered on 18 Mar 2010, 01:38 PM
Hi Miguel Rios,

The easiest way to bind the RadTreeViewItem's IsExpanded property to a property of your custom business object is to use ContainerBindingCollection. So if you want to expand certain items of your RadTreeView depending on the value of a boolean property  of your business object (for example, named IsExpanded), you only need to add the following binding collection:
<telerik:ContainerBinding PropertyName="IsExpanded"
                                                Binding="{Binding IsExpanded, Mode=TwoWay}"/>

If you want to change the selection mode of the RadTreeView to multiple, you need to set the SelectionMode property to Multiple. That will allow the user to select multiple items at one time by holding down the control key and clicking multiple items with the mouse or by using the keyboard. 

As for searching through the items of the RadTreeView, you can create a method, that traverse all the items of the tree. When the searched item is found  you can set the IsExpanded property of the displayed business object to True. Then you can set the background of the item to highlight it.

Please take a look at the example I attached and let me know if it helps or if you need more info.

All the best,
Tina Stancheva
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.
Asked by
Miguel Rios
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Share this question