Multiple selection

7 posts, 1 answers
  1. Vicente
    Vicente avatar
    3 posts
    Member since:
    Oct 2012

    Posted 11 Oct 2012 Link to this post

    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
  2. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 12 Oct 2012 Link to this post

    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.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Vicente
    Vicente avatar
    3 posts
    Member since:
    Oct 2012

    Posted 12 Oct 2012 Link to this post

    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
  5. Answer
    Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 17 Oct 2012 Link to this post

    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.

  6. Vicente
    Vicente avatar
    3 posts
    Member since:
    Oct 2012

    Posted 17 Oct 2012 Link to this post

    Hi Pavel,

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

    Vicente
  7. Sahi
    Sahi avatar
    2 posts
    Member since:
    Apr 2015

    Posted 22 Apr 2015 in reply to Pavel R. Pavlov Link to this post

    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>

     

     

  8. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 22 Apr 2015 Link to this post

    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.

     
Back to Top
UI for WPF is Visual Studio 2017 Ready