SelectedIndices Binding not working

Hey Guys,

I ran into a problem with the SelectedIndices-Property on SfComboBox-Control.

I work with MVVM.

Binding works from ViewModel to View but not the other way around.

XAML:

<comboBox:SfComboBox MultiSelectMode="Token" 
TokensWrapMode="Wrap"
IsSelectedItemsVisibleInDropDown="false"
Grid.Row="3" Grid.Column="1"
DataSource="{Binding Groups}"
DisplayMemberPath="GroupName"
SelectedIndices="{Binding SelectedGroups}"
VerticalOptions="Center"
HeightRequest="100">

ViewModel:

public ObservableCollection<OrganisationGroupModel> Groups
{
get => _groups;
set => SetProperty(ref _groups, value);
}
public ObservableCollection<int> SelectedGroups
{
get => _selectedGroups;
set => SetProperty(ref _selectedGroups, value);
}

Model:

public class OrganisationGroupModel
{
public int GroupId { get; set; }
public string GroupName { get; set; }

}

Any ideas, where I'm maybe doing something wrong?

Feature-Suggestion: Bindable SelectedItemsProperty since the Collection is already present in SelectionChangedEventArgs?!

Thanks in advance,

He


1 Reply

SS Suganya Sethuraman Syncfusion Team March 11, 2022 04:09 PM UTC

Hi Herbert,

We have analyzed the reported issue. SelectedIndices of SfComboBox currently only supports the List<int> type. Please use List<int> instead of ObservableCollection<int> in the SelectedGroups(ViewModel) property. Please add NotifyPropertyChanged to SelectedGroups(ViewModel) and use TwoWay binding in SelectedIndices of the SfComboBox as shown in the following code snippet.

Code snippet

XAML
 
        <combobox:SfComboBox  
                             MultiSelectMode="Token"  
                             TokensWrapMode="Wrap"  
                             IsSelectedItemsVisibleInDropDown="false"  
                             VerticalOptions="Center" 
                             HeightRequest="40"  
                             x:Name="comboBox" 
                             DataSource="{Binding EmployeeCollection}"  
                             DisplayMemberPath="Name"  
                             SelectedIndices="{Binding SelectedGroups, Mode=TwoWay}"/> 

ViewModel
 
       private List<int> selectedGroups; 
        public List<int> SelectedGroups 
                             { 
            get { return selectedGroups; } 
            set  
                                           { 
                                                          selectedGroups = value; 
                                                         this.OnPropertyChanged("SelectedGroups"); 
                                           } 
        } 


Please have the sample for your reference,

Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/ComboBoxSample_SelectedIndices-1734656977

Feature-Suggestion: Bindable SelectedItemsProperty since the Collection is already present in SelectionChangedEventArgs?!

Could you please elaborate on your requirement, as we were unaware of the exact application scenario? This will help us to investigate further and provide better solution at earliest.

Please check and let us know if you have any concerns.

Regards,
Suganya Sethuraman.
 


Loader.
Up arrow icon