SfComboBox SelectedIndex MVVM

Dear Support,

I am trying to implement a page in my project using the mvvm pattern. I have the following attributes:

private ObservableCollection comboSource;
private int comboDefault;

public ObservableCollection ComboSource
{
     get { return comboSource; }
     set
            {
                comboSource= value;
                OnPropertyChanged();
            }
}

public int ComboDefault
{
     get { return comboDefault; }
     set
            {
                comboDefault= value;
                OnPropertyChanged();
            }
}

I have the following xaml code
                                                 DataSource="{Binding ComboSource}"
                                                 DisplayMemberPath="Display"
                                                 SelectedIndex="{Binding ComboDefault}" />

I populate the attributes with a result from a REST web api. The bindings work fine, and the combobox is populated and the selectedindex is changed appropriately. When I clear the page, by resetting the attributes as follows,

ComboSource = new ObservableCollection();
ComboDefault = -1;

the combobox's datasource and selectedindex is updated accordingly and it works fine. When I however update the attributes for a second time, the combobox's datasource gets updated, but not the selectedindex. Both the attributes are updated accordingly in the viewmodel, which I can confirm by displaying the ComboDefault value in a label (

I am using the most recent version of syncfusion and sfcombobox (version 19.1.0.59), and xamarin forms version 5.0.0.1874.

Any help regarding this would be greatly appreciated.

Kind regards,
Jano

3 Replies 1 reply marked as answer

JK Jeya Kasipandi Syncfusion Team May 7, 2021 01:16 PM UTC

Hi JanoMillar,

Greetings from Syncfusion.

We have validated your query and we suggest you resolve the reported issue by setting Mode to two way in selected index property as like below code snippet
Xaml:
   <combobox:SfComboBox SelectedIndex="{Binding SelectedIndex,Mode=TwoWay}"  
DisplayMemberPath="PropertyName"
DataSource="{Binding EmployeeCollection}" >
</combobox:SfComboBox>

Please check with the above and let us know if you have any concern.

Regards,
Jeya K


Marked as answer

JA Jano May 10, 2021 06:18 AM UTC

Hi Jeya K,

Thank you so much for your support. I can't believe I didn't think of that, but anyways, my issue is resolved.

Regards,
Jano


SS Suganya Sethuraman Syncfusion Team May 11, 2021 04:49 AM UTC

Hi Jano,

Thanks for the update.

Please get back us if you need further assistance.

Regards,
Suganya Sethuraman.
 


Loader.
Up arrow icon