Multiselect Binding SelectedItems

4 posts, 0 answers
  1. Ates
    Ates avatar
    15 posts
    Member since:
    Nov 2010

    Posted 24 Oct 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
    586 posts

    Posted 25 Oct 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. UI for WPF is Visual Studio 2017 Ready
  4. Ates
    Ates avatar
    15 posts
    Member since:
    Nov 2010

    Posted 25 Oct 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

  5. Nasko
    Admin
    Nasko avatar
    586 posts

    Posted 28 Oct 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!
Back to Top