locked
Fill Picker from table RRS feed

  • Question

  • User395446 posted

    Greetings everyone i have no idea how to fill value of picker from table i have this table i'm using (c#markup)

    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

    _TypeRequst = new Picker();
                _TypeRequst.ItemsSource = db.Table<TypeRequstTB>().OrderBy(x => x.NameTypeRequest).ToList();
                _TypeRequst.Title = "NameTypeRequest";
                _TypeRequst.SelectedItem = "IdTypeReuqst";
                stackLayout.Children.Add(_TypeRequst);
    

    how can i get value and title from that table?!!

    Saturday, July 18, 2020 9:49 AM

All replies

  • User395446 posted

    anyone know how can i deal with that?

    Sunday, July 19, 2020 8:19 AM
  • User89714 posted

    @mhmqi said: Greetings everyone i have no idea how to fill value of picker from table i have this table i'm using (c#markup)

    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

    _TypeRequst = new Picker();
                _TypeRequst.ItemsSource = db.Table<TypeRequstTB>().OrderBy(x => x.NameTypeRequest).ToList();
                _TypeRequst.Title = "NameTypeRequest";
                _TypeRequst.SelectedItem = "IdTypeReuqst";
                stackLayout.Children.Add(_TypeRequst);
    

    how can i get value and title from that table?!!

    For setting the data for going in the Picker, see https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/picker/populating-itemssource#populating-a-picker-with-data-using-data-binding , in particular using ItemDisplayBinding

    It is unclear from your question what you want the Picker's Title set to. If you don't want the hard-coded string "NameTypeRequest" as the Title, can you clarify what you do want as the Title?

    Sunday, July 19, 2020 2:26 PM
  • User395446 posted

    i was thinking to make Item Display to be "NameTypeRequest" i think i need to learn more about ViewModel to manage my query is that right?

    Monday, July 20, 2020 6:06 AM
  • User89714 posted

    @mhmqi said: i think i need to learn more about ViewModel to manage my query is that right?

    Doing so provides you with more options and likely results in the design/architecture of your code improving.

    Monday, July 20, 2020 9:25 AM