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

Multiple selection

6 Answers 635 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Vicente
Top achievements
Rank 1
Vicente asked on 11 Oct 2012, 06:30 PM
Hi,

I have a ViewModel with a collection binded to my user control, and then one of the ViewModel properties is binded to a RadTreeView. I need to support multiple selection, but it seems I can't bind SelectedItems property. Any tips on how to achieve this?

Regards

6 Answers, 1 is accepted

Sort by
0
Pavel R. Pavlov
Telerik team
answered on 12 Oct 2012, 10:36 AM
Hello Vicente,

In order to achieve this you can bind  a boolean property of your ViewModels (ex. Selected) to the IsSelected property of the RadTreeViewItem via StyleBindings. For more information you can read this article.

Feel free to ask if you have any questions.

All the best,
Pavel R. Pavlov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Vicente
Top achievements
Rank 1
answered on 12 Oct 2012, 11:24 PM
Hi Pavel,

ok, I see how it works. But ideally what I would like to have is something like this. A ViewModel that has two properties:

- Items: the collection bound to the ItemsSource property of the tree.
- SelectedItems: the collection of selected items boud to the SelectedItems property of the tree (this is what I can't do as SelectedItems in RadTreeView does not have a public set).

If I went and added a IsSelected property to all my items, I would need somehow to have my items tell the ViewModel that contains the SelectedItems collection about changes on the IsSelected property so it is updated correctly. Is there not an easier way to handle this?

Regards,

Vicente
0
Accepted
Pavel R. Pavlov
Telerik team
answered on 17 Oct 2012, 02:07 PM
Hello Vicente,

You can achieve your goal by using System.Windows.Interactivity.Behavior<T>. Please take a look at the attached project and let us know if it works for you.

Regards,
Pavel R. Pavlov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Vicente
Top achievements
Rank 1
answered on 17 Oct 2012, 10:46 PM
Hi Pavel,

this has worked wonderfully, thanks a lot for providing the sample. Regards!

Vicente
0
Sahi
Top achievements
Rank 1
answered on 22 Apr 2015, 09:34 AM

Hi Pavel,

I wrote below show all the items selected but only last item is selected . I need to show multiple items selected at one time.

Before that i experimented like this below set of code . but it didn't work. Please help!

   <telerik:RadTreeView.ItemContainerStyle>

<Setter Property="IsSelected" Value="True" >

</telerik:RadTreeView.ItemContainerStyle>

 

 

0
Pavel R. Pavlov
Telerik team
answered on 22 Apr 2015, 10:54 AM
Hi Sahi,

I would like to turn your attention to the definition of the ItemContainerStyle. You should set that property to a Style targeting the RadTreeViewItem control. For example you can use this code:

<telerik:RadTreeView >
    <telerik:RadTreeView.ItemContainerStyle>
        <Style TargetType="telerik:RadTreeViewItem">
            <Setter Property="IsSelected"  Value="True" />
        </Style>
    </telerik:RadTreeView.ItemContainerStyle>
</telerik:RadTreeView>
Also, you need to configure the RadTreeView control to select more than one of its items. This can be done by using the SelectionMode property. By default this property is set to Single which forces the RadTreeView control to select only one of its items. In your case can try setting it to Multiple.

When this configuration is applied the earlier provided snippet it looks like this:

<telerik:RadTreeView SelectionMode="Multiple">
    <telerik:RadTreeView.ItemContainerStyle>
        <Style TargetType="telerik:RadTreeViewItem">
            <Setter Property="IsSelected"  Value="True" />
        </Style>
    </telerik:RadTreeView.ItemContainerStyle>
</telerik:RadTreeView>
I hope this information is helpful.

Regards,
Pavel R. Pavlov
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
Tags
TreeView
Asked by
Vicente
Top achievements
Rank 1
Answers by
Pavel R. Pavlov
Telerik team
Vicente
Top achievements
Rank 1
Sahi
Top achievements
Rank 1
Share this question
or