Multiselect Binding SelectedItems

6 posts, 0 answers
  1. Alex
    Alex avatar
    15 posts
    Member since:
    Nov 2010

    Posted 24 Oct 2016 Link to this post

    Hello

    How can I bind the selected Items from the Combobox when using "AllowMultipleSelection"?

    ItemTemplate: <CheckBox Content="{Binding Name}" IsChecked="{Binding RelativeSource={RelativeSource AncestorType=telerik:RadComboBoxItem}, Path=IsSelected}" />

    Sincerly

    A.Kasar

     

  2. Nasko
    Admin
    Nasko avatar
    693 posts

    Posted 25 Oct 2016 Link to this post

    Hello Ates,

    SelectedItems is read only property inherited from MultiSelector class, that is why it cannot be bound to a property in the ViewModel.

    What we could suggest you as one possible appraoch is to extend the functionality of RadComboBox using an attached property and add the desired items to the SelectedItems collection of RadComboBox. More detailed information how to extend the functionality you could find here:
    http://www.telerik.com/blogs/extending-the-functionality-of-radcontrols-with-attached-properties

    Attached you could find a sample that demonstrate the described in the blog post approach.

    Hope this helps.

    Regards,
    Nasko
    Telerik by Progress
    Do you need help with upgrading your WPF project? Try the Telerik API Analyzer and share your thoughts!
  3. Alex
    Alex avatar
    15 posts
    Member since:
    Nov 2010

    Posted 25 Oct 2016 Link to this post

    Hello

    thank you for your answer.

    I have tested your sample. The binded property SelectedAgencies does not update at runtime. It always contains the original / initial items. What do I have to change / add in order to have the updated response from the control? How does it get passed on in runtime to the SelectedAgencies correctly?

    Sincerly

    A.Kasar

  4. Nasko
    Admin
    Nasko avatar
    693 posts

    Posted 28 Oct 2016 Link to this post

    Hi Ates,

    The proposed in my previous response approach is just a simple one and you might need to continue improve it in order to make everything work as expected.

    So, in order your changes in the selection get notified to the collection itself you could use behavior instead of an attached property. Inside it you need to attach to the CollectionChanged event of the collection you are bound to and to the SelectionChanged event of the ComboBox. When selection is made the SelectionChanged event will be fired and you could update the collection you are bound to with the new item that is selected from RadComboBox.

    Please, check the attached sample that demonstrates that approach.

    We hope this will help you.

    Regards,
    Nasko
    Telerik by Progress
    Do you need help with upgrading your WPF project? Try the Telerik API Analyzer and share your thoughts!
  5. Rama
    Rama avatar
    1 posts
    Member since:
    Jun 2012

    Posted 12 Oct in reply to Nasko Link to this post

    Hi Nasko,

    I verified this code and wanted to use this in my application.

    The SelectedAgencies in the ViewModel is not updated with the selection of multiple items in the combo box.

    Can you please verify and update the code.

    Thanks

    Rama

  6. Dinko
    Admin
    Dinko avatar
    416 posts

    Posted 17 Oct Link to this post

    Hello Rama,

    I have examined the project and when you select items from the combo box the SelectedAgencies collection is populated correctly. I have modified the project to demonstrated that the collection is populated. You can find the project attached to this reply. When you run the project you can observe at the top a TextBlock which is bind to the Count property of the collection. Also in the view model, I have subscribed to the CollectionChanged. You can place a breakpoint in the event handler to see that the event is called.

    If I am in the wrong direction, can you elaborate more on what is not working on your side?

    Regards,
    Dinko
    Progress Telerik
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Back to Top