Scrolling ListView control to specific item
Is there a way to scroll a listview (in report view) so that a specific item is at the top? The closest I could find w开发者_开发问答as ListView_EnsureVisible, but that only ensures that the item is visible - it does not allow fine control over where the items appears.
ListView_EnsureVisible() scrolls the ListView to make the item visible, but it usually (but not always) places the item near the middle of the ListView. To make the item appear at the top, call ListView_EnsureVisible() first, then call ListView_GetTopIndex() to determine the top visible item, then use ListView_GetItemIndexRect() to retreive both item's heights and positions, then calculate the vertical offset between them, and finally call ListView_Scroll(). I do this in one of my own projects and it works fine.
精彩评论