Question

I am trying to get a list scrolled at the initial point after an action whose result is the removal of all items and repopulation.

I wanted to get the scroll position recorded and then set back to it but GetScrollPos always returns 0 for some reason.

I have been looking over all the ListCtrl methods but can't seem to find a way and also noticed GetScrollPos is not there but neither does it raise an exception.

Was it helpful?

Solution

I got it to work by calculating the bottom item and using EnsureVisible on the one above it since EnsureVisible always shows an extra item underneath the targeted one if there is any.

Works perfectly and no need for GetScrollPos since I'm pretty sure there is no SetScrollPos.

list_total  = list.GetItemCount()
list_top    = list.GetTopItem()
list_pp     = list.GetCountPerPage()
list_bottom = min(list_top + list_pp, list_total - 1)
list.EnsureVisible((list_bottom - 1))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top