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 next EnsureVisible()
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):
void CDlg::SetTopIndex(int top)
{
int bottom = min(top + m_List.GetCountPerPage(), m_List.GetItemCount() - 1);
m_List.SetRedraw(FALSE);
m_List.EnsureVisible(bottom, TRUE);
m_List.EnsureVisible(top, FALSE);
m_List.SetRedraw(TRUE);
}