CListCtrl: How to maintain scroll position?

前端 未结 2 426
面向向阳花
面向向阳花 2021-01-11 17:30

I have a CListCtrl (report style) where I clear the list and repopulate it at certain times. I\'d like to maintain the vertical scroll position when doing this. I see ther

相关标签:
2条回答
  • 2021-01-11 17:51

    Another way to do it is like so:

    CRect r;
    m_lcList.GetItemRect(0, r, LVIR_BOUNDS);
    int scrollPos = m_lcList.GetTopIndex() * r.Height();
    RenewContents();
    m_lcList.Scroll(CSize(0, scrollPos));
    
    0 讨论(0)
  • 2021-01-11 18:01

    I've done that in the past. IIRC, the trick consisted in:

    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
    
    0 讨论(0)
提交回复
热议问题