0
votes

I have a picker where I update the current address of the user/retailer. The selected value is from my database I want to set the selected item of my picker.

My XAML:

<local:CustomPicker x:Name="provincePicker" SelectedIndexChanged="provincePicker_SelectedIndexChanged" Unfocused="provincePicker_Unfocused" SelectedItem="{Binding DisplayText}" ItemsSource="{Binding ProvinceID}" ItemDisplayBinding="{Binding DisplayText}" StyleClass="fieldForm" IsEnabled="True">
<local:CustomPicker.FontFamily>
     <OnPlatform x:TypeArguments="x:String">
         <On Platform="Android" Value="HelveticaNeueLTPro-Lt.otf#HelveticaNeueLTPro-Lt"/>
     </OnPlatform>
</local:CustomPicker.FontFamily>

XAML.CS

var getCode = conn.QueryAsync<RetailerGroupTable>("SELECT * FROM tblRetailerGroup WHERE RetailerCode=?", code);
var resultCount = getCode.Result.Count;

if (resultCount > 0)
{
   var result = getCode.Result[0];
   provincePicker.SelectedItem = result.ProvinceID;
}
1
to start with, ItemsSource="{Binding ProvinceID}", it doesn't appear that you are setting your ItemsSource correctly. It should be set to some IEnumerable, not a single value. Then SelectedItem should be set to an element from the ItemsSource CollectionJason
@Jason can you show me how to fix this?user10200885
@Jason I can list the provinces but I cant select value from my databaseuser10200885
are you also assigning ItemsSource in code?Jason

1 Answers

0
votes

These are the key properties involved in configuring a Picker

  • ItemsSource this should be an IEnumerable<T>, ie a List<MyClass> or ObservableCollection<MyClass>
  • SelectedItem - this should be set to an object that is contained in the ItemsSource collection
  • ItemDisplayBinding - this is the name of a Property of MyClass that will be displayed to the user in the Picker