Pre-selecting (highlighting) an item when ListPicker is opened

Hi there,
there is a ListPicker in my app that contains many items. However, when the user selects an item and re-opens the ListPicker at a later time, the chosen item is not selected anymore and the list always starts with an offset of 0, so the user has to scroll all the way down and search for his previously picked item.

Is it possible to

  • automatically scroll the list to a certain item when opened and

  • highlight that item to show what the user's current choice is until he selects another item?

Use these blocks.
They should solve your problem

1 Like

@Alaqmar_Bohori I think you don't need to use that :sweat_smile:

Didn't get you :thinking:

do you understand now :wink:


But I am setting the selection right, not the selection index :grimacing:

okay, sorry it's my mistake :sweat_smile: :+1:

1 Like

Great, thanks for helping me out :+1:

By the way - what's the best place to fill a ListPicker programmatically at app start? Currently I use MyList.BeforePicking() to fill a ListPicker with a list of variables. But I feel that Screen.Initialize() would be a better place, wouldn't it? The list only needs to be filled once the list items do not change afterwards.

yeah Mee too

Hm, I can't get it to work - what's wrong here? :thinking:

I also tried .selectionIndex instead of .selection but this doesn't work either.

The previously chosen item is still not highlighted in the list and the list still shows up without any scroll offset, always showing the very first element.

ListPicker has no marked selection. ListView has them, but also doesn't work properly and has been repaired for a year. You won't do what you want with the standard ListPicker.

can you show all your blocks, and I think (BeforePicking) works like (when screen.initialize),
so I recommend you to save the value to TinyDB

Example :


But Screen.Initialize is called once only, so this wouldn't work :confused:

BeforePicking should work according to the docs:

Event to raise when the ListPicker is clicked or the picker is shown using the Open method. This event occurs before the picker is displayed, and can be used to prepare the picker before it is shown.

BeforePicking is indeed called each time the user clicks the ListPicker to open the list. I tested this by playing a sound in the BeforePicking block. But for some reason the set .selection to is ignored.

Could this probably be a platform related issue? I am testing on Android 7.

Here's a snapshot of all blocks:

@Patryk_F has already correctly advised you that you cannot preselect a selection programmatically for a listpicker.

You can do this with a listview, therefore consider using a listview, and program its behaviour to be like that of a listpicker. (set to empty list makes a listview disappear)

But it seems to work for Salman_Dev for some strange reason.

Anyway, switching to a ListView would be too much effort for my little app. I'll leave it as it is and keep this in mind for the next project then :neutral_face:

He is showing blocks with a ListView :wink: