Remember and restore a CListCtrl Horizontal Scroll Position

Posted on 2006-06-02
Last Modified: 2013-11-20
I'm trying to remember and restore a list control's horizontal scroll position in my dialog.

The list control displays calibration data. If new cal data is captured, the list control's contents are deleted and completely redrawn with the new data (not the best way to do things, I know...but I don't have time to redo all of that...). My users want to be able to watch a certain "area" of the list control while collecting cal data and not have to constantly rescroll back to the area under observation.

I've tried a few things that I've seen here to no avail.
I've tried using get/set scroll info but that only works to a point...the scroll bar returns to the proper position but the contents of the list control do not follow - like the list control view is disconected from the scroll.

I've tried using the .Scoll member using the nPos value of a SCROLLINFO struct. There seems to be some offset problem with it, in that as I try to restore the position for info that is out of the client area of the control, the view of the data that I want to see is less and less correct. (If that makes any sense...).


Question by:jhorstkamp
    LVL 22

    Expert Comment

    You are restoring scroll positions. but i think probably you are not updating new scroll factors related to your new contents in list control...such as scroll range .. your scroll range is dependent on list control contents ?

    You should update scroll info struct depending on your new list control contents..


    Author Comment

    I tried your suggestion. No luck...

    Do I have to do something with the page information - ie calculate the scroll position from what page the thumb was on?

    (I don't know why this has to be so frustratingly obtuse to figure out!!)


    LVL 22

    Accepted Solution

    actually you may try by setting thumb page size using SetScrollInfo()...

    Try this simple suggestion :
    If your total contents in listbox are lets say 100 pixel units and your list control window size is 30 units then try by setting scroll range :100 and Thumb Page Size : 30


    Author Comment

    Actually, this works:

    void CCalibrateDialog::LoadCalibrationDataToList()
          m_si.cbSize = sizeof(SCROLLINFO);
          m_si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE | SIF_TRACKPOS;
          m_ListCalPoints.GetScrollInfo(SB_HORZ, &m_si, SIF_ALL);
          m_position = m_ListCalPoints.GetScrollPos(SB_HORZ);
                   // Repopulate the list control here...


    I don't know why the .Scroll member of the list control works with a single int since it specifies a CSize variable as the pass parameter - but it does...

    I don't know why get/set scroll position don't scroll the client area they are supposed to be "attached" to. Why would you want to just move the thumb around - especially in a list control that DOES have a client area?

    Anyway, points go to MAHESH. You didn't give me an explicit answer, but your comments at least helped spur some experiments...



    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    cat dog challenge 18 119
    bobThere java chalenge 45 75
    Whole sheet autoscrub still needed 19 41
    centeredAverage challenge 8 89
    In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
    Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now