Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Greetings everyone
i have no idea how to fill value of picker from table i have this table
i'm using (c#markup)

C#
class TypeRequstTB
    {
        public int IdTypeReuqst { get; set; }
        public string NameTypeRequest { get; set; }
    }



and i want get value from this field (IdTypeReuqst) and i want display title from this field (NameTypeRequest)
so i did this code but still not get me as i want

What I have tried:

C#
_TypeRequst = new Picker();
_TypeRequst.ItemsSource = db.Table<TypeRequstTB>().OrderBy(x =>x.NameTypeRequest).ToList();
_TypeRequst.Title = "NameTypeRequest";
_TypeRequst.SelectedItem = "IdTypeReuqst";
stackLayout.Children.Add(_TypeRequst);
Posted
Updated 19-Jul-20 23:52pm

1 solution

Setting a Picker's ItemsSource Property - Xamarin | Microsoft Docs[^]

You need to set the Picker.ItemDisplayBinding[^] to specify the property you want to display, and bind the Picker.SelectedItem[^] property to a property containing the selected instance of your class.

If you want to bind the selected item based on the ID, rather than an instance of your class, you'll need a custom control. For example:
Xamarin Picker with ID-based Binding[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900