Jumping to top of Listview programatically

Andras

Active Member
Licensed User
Longtime User
The heading says it all; I have a Listview within a Scrollview, and all works fine, but how can I ensure that the top item is the one which is always visible when the list is shown?

Thanks!

John
 

Andras

Active Member
Licensed User
Longtime User
Thanks, Desolate.

I note that SetSelection isn't listed among the members in the Guide, though it does appear as an item in the pop-ups.

More seriously, it doesn't actually seem to do what I want (or anything, actually!) which is to ensure that if the user scrolls down to the bottom of a long list of items, then backs out, then returns with a short list, those few items will be immediately visible, rather than having disappeared off the top of the ListView.

So now I'm really puzzled!

John
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
Oh, I didnt notice you have a listview inside a scrollview!
I tried that, and the listview cannot scroll, but you can set the topmost item with SetSelection.
klaus is right, you need to use ScrollPosition.
Btw...it is not a great idea to have a listview inside a scrollview since the listview size can change dynamically.
 
Upvote 0

Andras

Active Member
Licensed User
Longtime User
Yes, ScrollPosition works. Many thanks!

The situation is that I have a list which is longer than the screen, so is accommodated within a ScrollView; I can control the ListView size appropriately, so there seem to be no problems there, though I accept that it may be a bit of a kludge.

But is there a better way of achieving the same result? As must be obvious, I'm really still finding my feet in this environment!

John
 
Upvote 0

Andras

Active Member
Licensed User
Longtime User
You do realise that a ListView is scrollable on its own without a scrollview?

Indeed - it just seemed the simplest way to control its appearance on the screen at the time I was writing it, especially as I was just getting to grips with scrollview at the time!

John
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
There is no reason to have a ListView in a Scrollview.
You should use either a ListView, faster but with limitations (two labels and a bitmap), or a ScrollView somewhat slower but much more versatile (almost everything is possible).

Best regards.
 
Upvote 0
Top