Working With Bindable SelectedItems Collection in RadTreeView

3 posts, 1 answers
  1. Stacey Haslag
    Stacey Haslag avatar
    30 posts
    Member since:
    Oct 2009

    Posted 16 Feb 2011 Link to this post

    I am using the RadTreeView control for the first time. I am using the MVVM approach to interact with this control. What I want to do is be able to set and get the SelectedItems of the RadTreeView. I am allowing multiple selections to occur. I have the initial heirarchy list of business objects that I bind to the control. But I can't find a way to neatly interact with a collection of the selected items.

    I have read a lot of the various instructions in this area They lead me to using the ContainerBindingCollection and HierarchicalDataTemplate approach. So I have done this, and this is binding my collection of datasource business objects appropriately. 

    However, this still does not get me exactly what I want. Maybe it is not possible, but what I would like is a way to bind to the SelectedItem property, and receive a collection of selected items; and vice-verca to Set the SelectedItem list, and have the appropriate items selected.

    With the way that it is set up using the ContainerBindingCollection approach, I don't see a way to do that...would I have to build my own collection of selected items one-by-one as they select them?

    Here is my XAML:

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

    <telerik:RadTreeView Margin="0, 20, 0, 20" SelectionMode="{Binding SelectionMode}" ItemsSource="{Binding SortedTableOfContentsList}"
                                 SelectedItem="{Binding SelectedPage, Mode=TwoWay}">
                    <telerik:HierarchicalDataTemplate ItemsSource="{Binding RelatedPages}" 
                                                      telerik:ContainerBinding.ContainerBindings="{StaticResource BindingsCollection}">
                        <StackPanel Orientation="Vertical" VerticalAlignment="Bottom">
                            <TextBlock Text="{Binding Description}"></TextBlock>
                            <TextBlock FontSize="9" Text="{Binding Notes}" Margin="10, 0, 0, 0"></TextBlock>

    Notes: I do get all my heirarchy items to show in my tree list appropriately. I do have an "IsSelected" property added to my business object for binding. I am getting my "SelectedPage" property to fire in my view model for each item that is just fires one at a time as items are selected individually.


  2. Answer
    Petar Mladenov
    Petar Mladenov avatar
    3152 posts

    Posted 21 Feb 2011 Link to this post

    Hi Stacey Haslag,

    First I would like to note that in Extended selection mode, the SelectedItem is always the first item in the SelectedItems collection: SelectedItems[0]. However, could you please examine this blog post showing a possible way to synchronize the SelectedItems colelction with a collection of business items in the ViewModel.
    Please let us know if this approach fits in your scenario.

    Kind regards,
    Petar Mladenov
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  3. Stacey Haslag
    Stacey Haslag avatar
    30 posts
    Member since:
    Oct 2009

    Posted 04 Mar 2011 Link to this post

    Sorry for the late response to this! Yes, this scenario does fit my situation; I am now able to interact with the SelectedItems collection. Thanks for your help!

Back to Top