The list-view control has the LVM_GETTOPINDEX
message that allows to get the index of the topmost visible item.
Now I need to set the topmost visible item, but surprisingly there is no LVM_SETTOPINDEX
message which would be natural.
Is there an easy clean way to set the topmost item?
My list-control is always in report mode.
First, it may NOT be possible. For example, if the list doesn't have enough items after your top index to fill the page.
As there is no direct way, you can count the number of items on the page, add that count to your index and call
EnsureVisible()
. This will make your sure that your top is above visible page. The nextEnsureVisible()
for your item will bring it into the view, at the top of the page. Of course, you would need to block updates to avoid jerking of the screen.Example (updated by Vlad):
LVM_GETITEMPOSITION
orLVM_GETITEMRECT
to obtain the items position.LVM_SCROLL
to scroll the list so that your item is the top item.This function does the job:
No parameter sanitation is done here.
Thanks to David Heffernan and Remy Lebeau for giving me the idea.