C1MultiSelect bind SelectedItemsList from ViewModel

Posted by: fernando.ortiz on 15 September 2020, 6:51 pm EST

    • Post Options:
    • Link

    Posted 15 September 2020, 6:51 pm EST

    Hello !

    I’m trying to work with C1MultiSelect component and MVVM pattern in an wpf application. My problem is when i try to bind the multiple selected item list to the control for load a default selection, the propoerty SelectedItems is readonly.

    ¿How can i bind multiple selection list to control?

    Many thanks for help.

    Regards!

    Fernando Ortiz

  • Posted 19 September 2020, 7:35 pm EST

    Hello Fernando,

    Apologies for the delay.

    You can use the SelectedValuePath property to bind multiple selection in the control. Please refer attached application for the same.

    Regards,

    Ruchir

    MultiSelect_MVVM.zip

  • Posted 20 September 2020, 7:19 pm EST

    Hi Ruchir

    I am looking at the example but there are some things that I do not understand.

    First of all, the property you mention to me, ‘SelectedValuePath’, is not being used in the example project. I also don’t see the ViewModel’s observable collection, ‘SelectedItems’, being used anywhere. I can’t see how that property is related to the view.

    On the other hand, I see that the correct items appear selected in the component, but the selection tags do not appear in the multiselect text. Am I overlooking something?

    Thank you very much for all the help,

    Regards,

    Fernando Ortiz

  • Posted 21 September 2020, 9:43 pm EST

    Hello Fernando,

    Apologies its the CheckedMemberPath property you should use. Also, the SelectedItems collection is redundant in the scenario, as the selection is based on the IsSelected property of Model.

    To show the selection tags to appear in multiselect control, set the DisplayMode property to Tag.

    I have attached the modified application for reference.

    Thanks,

    MultiSelect_MVVM_Modified.zip

  • Posted 17 November 2020, 7:37 pm EST

    Hello there,

    the code sample from the post marked as answer doesn’t work correctly at our end, because the initially selected items are not shown in the C1MultiSelect until the user manually opens the dropdown. Only then the items are rendered, beforehand nothing shows up at all.

    We observe the same behavior in our application when we initially select items, which is confusing for our users because they expect to see them as soon as the control is rendered (just like a TextBox with pre-filled text).

    Regards,

    Lars

  • Posted 18 November 2020, 8:13 pm EST

    Hi Lars,

    I got your concern and can observe it as well.

    To resolve that, since the SelectedItems property in C1MultiSelect is not a Dependency property we cannot bind it. However, you can add a custom DependencyProperty in code, use it to pass items to SelectedItems collection and then, use this custom DependencyProperty as AttachedProperty in XAML.

    For your reference, I have modified the application used in the post above and attached here for your reference.

    Regards,MultiSelect_MVVM_SelectionOnLoad.zip

  • Posted 8 December 2020, 6:41 pm EST

    Hello there,

    sorry for my late response. In the meantime I applied your solution and it works. Having a SelectedItems would be nicer, though, because we typically have a base collection coming from a web service where the user can choose items from (e.g. users) and another collection where we store the actual selection (e.g. selected users).

    To mimic this behavior (similar to a normal ComboBox), I created a derived MultiSelect control.

    Thanks and best regards

    Lars

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels