Link to home
Start Free TrialLog in
Avatar of winmeister
winmeisterFlag for Italy

asked on

Programmatically scroll in CListView

In a CListView, I can programmatically select an item by this instruction:

ListCtrl.SetItemState(nItem,LVIS_SELECTED|LVIS_FOCUSED,LVIS_SELECTED|LVIS_FOCUSED);

The matter is that if the item is not  currently in  view, the list control doesn't scroll.

Another problem (but reltaed to the first one) is that MFC has a CListCtrl::GetTopIndex() function, but doen't have the corresponding SetTopIndex().

How can I programmatically scroll the events in the ListCtrl associated with a CListView?

Avatar of Tommy Hui
Tommy Hui

Use CListCtrl::EnsureVisible(). You can make sure an item is visible and whether partially visible is okay or not.
Avatar of winmeister

ASKER

This is only partially true. How can I get the item as the first in the scroll view? I mean, I'd like to have a function similar to SetTopIndex(nItem).......
ASKER CERTIFIED SOLUTION
Avatar of Melange
Melange
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial