Multiselect mode, what is the best way to get the value?

I'm using MVVM pattern and tried using SelectedItem binding property to get the value, but it doesn't work if it's Multiselect mode enabled.
Then, I decided to use Behavior,

                                <combobox:SfComboBox.Behaviors>
                                    <prism:EventToCommandBehavior Command="{Binding ChangeMyModelCommand}"
                                                                  EventName="SelectionChanged"
                                                                  EventArgsParameterPath="Value" />
                                </combobox:SfComboBox.Behaviors>


In ViewModel, I decided to serialize and then deserialize the object.

        public void ChangeMyModelCommandAction(object obj)
        {
            var myModel = JsonConvert.SerializeObject(obj);
            MyModel = JsonConvert.DeserializeObject<List<MyModel>>(myViewModel);
        }

Is there a better approach?








3 Replies 1 reply marked as answer

SR Shivani Ramakrishnan Syncfusion Team September 27, 2022 11:55 AM UTC

Hi Felipe,


Query 1: Using SelectedItem as binding property to get the value, when MultiSelected mode is enable


We have looked into your query. We have used SelectedItem as binding property to get and set the value when MultiSelect mode is enabled. The selected item is working properly. We have prepared a sample for your reference and please get it from the attachments.


Query 2: Serialize and then Deserialize the object approached. Is there a better approach?


Yes, we can use this approach in the code.  Kindly let us know if you need any other information


Regards,

Shivani


Attachment: MultiSelectMode_a9720abc.zip

Marked as answer

FE Felipe September 27, 2022 03:14 PM UTC

Thanks a lot, it worked, I didn't know that we shoud use an object to SelectedItem property, I was using a List<MyModel>



RS Ruba Shanmugam Syncfusion Team September 28, 2022 10:08 AM UTC

Hi Felipe,


We are glad to know that the given solution works for you. We suggest you use the object data type instead of other data types for the SelectedItem property.  


Kindly let us know if you need any other details.


Regards,

Ruba Shanmugam


Loader.
Up arrow icon