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
10 Answers, 1 is accepted
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

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
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

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
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

Dinko,
I am looking for something just like this, however after trying your behavior code, you still cannot set the SelectedItems property on the RadComboBox. When I try to do this I always get a -1 result, meaning it was not able to add the item to the collection. Is this as designed or is there another way to set the binding?

I am not sure that I have fully understood your scenario. I am assuming that you are adding the custom Behavior runtime. I have tested this in the attached project and was able to set the binding runtime. Check the modified version of my project. When you run the project you can observe that the TextBlock is not updated while you are selecting items from the drop-down. Select a few items and press the button. In the Click event handler, I am adding the SelectedItemsBehavior to the Behaviors collection of the RadComboBox. Now when you select items the collection from the view model is updated.
Can you take a look at this project and let me know if it works on your side. If not, can you elaborate more on your case? How are you setting the custom behavior?
Regards,
Dinko
Progress Telerik

I have a behavior that does indeed populate the Collection of SelectedOptions on my ViewModel, BUT what I need to do is call an event when they are updated as I have another list that is built from the selections in my MultiSelect RadComboBox. How can I capture the change to the SelectedOptions Collection as it is of type ObservableCollection without PropertySet capabilty and therefore never raises the property changed event on the property.
Is there a way to capture each event when an Option is added to the collection?
Hi Billy,
I think the SelectionChanged event of the control is what you are looking for, but still, I am not sure. Can you try it and let me know if it fits in your case.
Regards,
Dinko
Progress Telerik
Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.