We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Unhandled index out of range expection when setting datasource

Dear support,


I updated the SfComboBox nuget package to the latest version, version 20.3.0.47. I am using Xamarin forms version 5.0.0.2012. When I add items to the ObservableCollection which I binded to the DataSource property of the SfComboBox, there is an unhandled exception and the app crashes. The error details are:


System.ArgumentOutOfRangeException

  Message=Index was out of range. Must be non-negative and less than the size of the collection.

Parameter name: index


I get the error when I do the following:

Class:

public class Test

{

    public int ID { get; set; }

    public string Description { get; set; }

}

In ViewModel:

private ObservableCollection<Test> list;

public ObservableCollection<Test> List

{

    get { return list; }

    set

    {

        list = value;

        OnProperyChanged();

    }

}


public ViewModel()

{

    List = new ObservableCollection<Test>();

    list.Add(new Test { ID = 1, Description = "Test" });

}


In XAML:

<inputLayout:SfTextInputLayout ContainerBackgroundColor="Transparent"

                                                               Hint="Test">

                                    <combobox:SfComboBox ShowSuggestionsOnFocus="True"

                                                         HeightRequest="65"

                                                         BorderColor="Red"

                                                         DisplayMemberPath="Description"

                                                         SelectedValuePath="ID"

                                                         DataSource="{Binding List}"/>

                                </inputLayout:SfTextInputLayout>


1 Reply

RS Ruba Shanmugam Syncfusion Team October 6, 2022 07:58 AM

Hi Jano,


Query: Unhandled index out of range expection when setting datasource


We have checked the reported query and we have already fixed the issue in our latest version. Could you please check your application with the latest version of SfComboBox 20.3.0.48 and let us share the details if you still facing the same problem?


Regards,

Ruba Shanmugam


Loader.
Live Chat Icon For mobile
Up arrow icon