Link to home
Start Free TrialLog in
Avatar of jhorstkamp
jhorstkamp

asked on

Remember and restore a CListCtrl Horizontal Scroll Position

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...).

Thanks,

John
Avatar of mahesh1402
mahesh1402
Flag of India image

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..

-MAHESH
Avatar of jhorstkamp
jhorstkamp

ASKER

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!!)

John


ASKER CERTIFIED SOLUTION
Avatar of mahesh1402
mahesh1402
Flag of India 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
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);
      
      //************************************************************
      
      m_ListCalPoints.DeleteAllItems();
               
                //****************************************
               // Repopulate the list control here...
               //****************************************

               //*******************************************
      m_ListCalPoints.Scroll(m_position);
      m_ListCalPoints.UpdateWindow();
}

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...

John