Use*_*ser 10 mfc scroll clistctrl
我有一个CListCtrl(报告样式),我清除列表并在特定时间重新填充它.这样做时我想保持垂直滚动位置.我看到有几种方法看起来很有希望:
EnsureVisible()
GetScrollPos()
SetScrollPos()
GetScrollInfo()
GetTopIndex()
Scroll()
Run Code Online (Sandbox Code Playgroud)
我正在尝试GetScrollPos()然后尝试SetScrollPos()但它似乎没有工作.保存滚动位置然后恢复它的简单正确方法是什么?
UPDATE
实际上我似乎可以保存滚动位置GetScrollPos()然后SetScrollPos()来恢复它,但它实际上似乎只是设置滚动条位置,并没有实际滚动我的CListCtrl的项目.
更新2
Scroll()方法似乎正确滚动滚动条和内容.然而,它需要一个CSize对象作为它的参数.所以问题是如何在CSize和GetTopIndex或GetScrollInfo/Pos的输出之间进行转换.
Ser*_*ier 17
我过去做过那个.IIRC,诀窍包括:
int topIndex= m_List.GetTopIndex();
RenewContents();
m_List.EnsureVisible(m_List.GetItemCount() - 1); // Scroll down to the bottom
m_List.EnsureVisible(topIndex);// scroll back up just enough to show said item on top
Run Code Online (Sandbox Code Playgroud)