How to preselect an item in Combo Box

Hi,

Not sure why I can't figure this out.  I have a list of 5 items in an SFComboBox.  When I start my app I want the first item in the list to be already selected.  I have tried:

 <combobox:SfComboBox HeightRequest="40" x:Name="comboBox" SelectedIndex="0">

And still the ComboBox is blank when I open my app.  

I couldn't find anything in documentation on how to show a default value/selection when the app is opened.

Please advise what I am missing.  Thank you


2 Replies

RT Robert Twickler August 2, 2021 08:53 PM UTC

Opps. My bad.  The new Xamarin Forms template uses a theme matching background. I use a dark background on my phone theme to save battery.  The text in the ComboBox was black and didn't show up.  

Probably something to be aware of that the controls with black text will not show up with the a black theme on the phone.  Maybe someday the controls will detect theme or background and automatically switch fore color...



SS Suganya Sethuraman Syncfusion Team August 3, 2021 06:26 AM UTC

Hi Robert,

Greetings from Syncfusion.

We have analyzed your requirement. We have achieved your requirement by using SelectedItem property of SfComboBox as below code snippet,

Code Snippet:
 
        <combobox:SfComboBox HeightRequest="40" 
                             x:Name="comboBox"  
                             DataSource="{Binding EmployeeCollection}"  
                             DisplayMemberPath="Name"  
                             SelectedItem="{Binding SelectedItem, Mode=TwoWay}"/> 

Please ha
ve a sample for your reference,

Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/SfComboBoxSelected-2073779244

Please check if the sample satisfies your requirement and let us know if you have any concerns.

Regards,
Suganya Sethuraman.
 


Loader.
Up arrow icon