Unable to update the ComboBox.SelectedItem in the UWP

Amulya 41 Reputation points
2021-12-22T14:13:31.927+00:00

Unable to update the ComboBox.SelectedItem in the UWP

We are unable to update the Combox.SeletedItem when the app is launched and no event has occured with that Combo box.
But we are able update when there is any event triggered in the App front end.

After the event trigger from the App front end of the combobox then we are able to update the comboBox.SelectedItem but not as soon as the app is launch.

We are getting the below mentioned error: Value does not fall in the expected range

NOTE:

  1. We are Binding the comboBox like mentioned below.

<ComboBox BorderThickness="1" Name="chkallComboBox" BorderBrush="#707070" ItemsSource="{x:Bind selectAllData}" SelectionChanged="chkallComboBox_SelectionChanged" PlaceholderText="--Select--" ItemContainerStyle="{StaticResource ComboBoxItemStyle1}"/>

  1. The mentioned line we are using for updating the combox.SeletedItem in UWP cs, which is working after any trigger in the comboBox but not on the Page load

chkallComboBox.SelectedItem = "Select All";

Universal Windows Platform (UWP)
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Nico Zhu (Shanghai Wicresoft Co,.Ltd.) 12,856 Reputation points
    2021-12-23T03:49:34.007+00:00

    Hello,
    Welcome to Microsoft Q&A!

    Unable to update the ComboBox.SelectedItem in the UWP

    Please check Combobox style, the listview part was placed in the popup control, it means that the listview will be lazy load. if you don't open the dropdown. the listview part will not render. If you want set SelectedItem , you may need show the droplist fist then set SelectedItem

    For example

     chkallComboBox.IsDropDownOpen = true;  
     chkallComboBox.IsDropDownOpen = false;  
     chkallComboBox.SelectedItem = selectAllData[0];  
    

    Thank you.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments