Problem with Picker list items

abvabv USMember ✭✭✭
edited August 13 in Xamarin.Forms

Hi,

I am adding itemssource to picker programmatically in uwp application like

List<Devices> devices = new List<Devices>();
devices = App.DAUtil.GetDevices();
picker.ItemsSource = deviceTypes;

devices list is adding to picker multiple times, I am not able to find the problem. Please help me for solving this.

Answers

  • JohnHardmanJohnHardman GBUniversity mod

    @abv said:
    Hi,

    I am adding itemssource to picker programmatically in uwp application like

    List<Devices> devices = new List<Devices>();
    devices = App.DAUtil.GetDevices();
    picker.ItemsSource = deviceTypes;
    

    devices list is adding to picker multiple times, I am not able to find the problem. Please help me for solving this.

    What is deviceTypes? Where is it initialised?

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭
    I think you should use devices, not devicetypes
  • abvabv USMember ✭✭✭

    Hi @JohnHardman @AlessandroCaliaro deviceTypes is my typing mistake.

    picker.ItemsSource = devices;

  • JarvanJarvan Member, Xamarin Team Xamurai

    Add breakpoints to check the content of 'devices' getting from App.DAUtil.GetDevices().

  • abvabv USMember ✭✭✭

    Hi @Jarvan I am getting my devices count fine.My problem is after adding devices to the picker, picker is scrolling continuously.

  • JarvanJarvan Member, Xamarin Team Xamurai

    @abv
    Could you post the related code or share a basic demo to reproduce the issue?

  • JohnHardmanJohnHardman GBUniversity mod

    @abv said:
    Hi @JohnHardman @AlessandroCaliaro deviceTypes is my typing mistake.

    picker.ItemsSource = devices;

    Please copy and paste code into posts, do not re-type selected bits of it.

    You have not posted enough code for anybody to give you a definitive answer. From the tiny piece that you have shown:
    (1) Replace List with an ObservableCollection
    (2) Post the definition of Devices (does one instance really contain multiple devices, or should Devices actually be Device)?
    (3) Post the definition of picker

  • abvabv USMember ✭✭✭
    edited August 14

    @Jarvan @JohnHardman I am taking one picker like

    <Picker x:Name="picker" HorizontalOptions="Center" VerticalOptions="CenterAndExpand" ItemDisplayBinding="{Binding DeviceName }"/>

    My Devices class is like

     public class Devices
        {
            [PrimaryKey, AutoIncrement]
            public int Id { get; set; }
            public string DeviceName { get; set; }
        }
    

    Now I am adding picker itemssource like

    List<Devices> devices = new List<Devices>();
    devices = App.DAUtil.GetDevices();
    picker.ItemsSource = devices;
    

    here I am getting devices list from my local db. When ever I run the code in windows ToughPad the picker items are scrolling continuously but it is working fine when I run the code in Local Machine.

  • JohnHardmanJohnHardman GBUniversity mod
    edited August 14

    As it doesn't show in the post by @abv above, the actual text of the post said:

    "When ever I run the code in windows ToughPad the picker items are scrolling continuously but it is working fine in Local Machine."

    @abv - I don't have a ToughPad, so cannot test this. You might want to raise a ticket with support - see https://forums.xamarin.com/discussion/150917/the-microsoft-xamarin-support-team-is-here-to-help#latest

    BTW, although it won't resolve this, you should consider renaming your Devices class as it only contains details of one device, not multiple devices. That'll save confusion when somebody looks at your code in future. Obviously, Xamarin.Forms already has a Device class, so you might want to find another name.

  • abvabv USMember ✭✭✭

    @JohnHardman thanks for the suggestion. :)

Sign In or Register to comment.