(Prerelease 2.5.20173.238) - Default C1ComboBox SelectedIndex Causing Exception

Posted by: jared.fritsch on 15 December 2017, 1:23 am EST

    • Post Options:
    • Link

    Posted 15 December 2017, 1:23 am EST

    On a lot of my C1ComboBoxes, I am setting a default SelectedIndex.

    <input:C1ComboBox
        x:Name="MyComboBox"
        SelectedIndex="0" />
    

    This throws an “Object reference not set to an instance of an object” exception. I tried setting the SelectedIndex in code instead, and received the same exception.

    public MyView()
    {
    	InitializeComponent();
    
    	MyComboBox.ItemsSource = _myDataSource;
    	MyComboBox.SelectedIndex = 0;
    }
    

    But, if I set the SelectedIndex within some other event, it seems to work just fine.

    private void MyButton_OnClicked(object sender, EventArgs e)
    {
            MyComboBox.SelectedIndex = 0;
    }
    

    I am using v2.5.20173.238 (pre-release as of this writing)

  • Posted 15 December 2017, 2:17 am EST

    Ok thanks Jared. We’re pushing 238 live today, but I’ll report this issue for that build. I wonder if Xamarin changed something in 2.5 that caused it since there weren’t a lot of other changes to Input. Is this UWP you’ve noticed it on or all platforms?

  • Posted 15 December 2017, 2:48 am EST

    Sorry, I don’t know why I keep forgetting to mention the platform. The tests above were done in UWP. Running this on Android gives a different behavior. It doesn’t throw an exception, but it doesn’t actually do anything. The ComboBox acts as if nothing is selected. Setting the SelectedIndex within some other event works fine though, just like UWP. I have not tested on iOS.

  • Posted 15 December 2017, 3:14 am EST

    Thanks. I have a feeling that a workaround for your issue would be to set the selected appearance in the Appearing event for your page. Though I haven’t tested it I remember similar issues I’ve had in Xamarin in the past that have been solved using this technique. We’ll research it though and I’ll see if we can put a fix together for it.

    Kelley

  • Posted 24 January 2018, 3:22 am EST

    Hi Jared

    This should be fixed in build 2.5.20173.241 which is now live on nuget.org.

    Thanks

    Kelley

  • Posted 26 January 2018, 6:27 am EST

    Works great - thanks, Kelley!

Need extra support?

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

Learn More

Forum Channels