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
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
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Actually, this works:
void CCalibrateDialog::LoadCali brationDat aToList()
{
//************************ ********** ********** ********** *****
m_si.cbSize = sizeof(SCROLLINFO);
m_si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE | SIF_TRACKPOS;
m_ListCalPoints.GetScrollI nfo(SB_HOR Z, &m_si, SIF_ALL);
m_position = m_ListCalPoints.GetScrollP os(SB_HORZ );
//************************ ********** ********** ********** ******
m_ListCalPoints.DeleteAllI tems();
//************************ ********** ******
// Repopulate the list control here...
//************************ ********** ******
//************************ ********** *********
m_ListCalPoints.Scroll(m_p osition);
m_ListCalPoints.UpdateWind ow();
}
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
void CCalibrateDialog::LoadCali
{
//************************
m_si.cbSize = sizeof(SCROLLINFO);
m_si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE | SIF_TRACKPOS;
m_ListCalPoints.GetScrollI
m_position = m_ListCalPoints.GetScrollP
//************************
m_ListCalPoints.DeleteAllI
//************************
// Repopulate the list control here...
//************************
//************************
m_ListCalPoints.Scroll(m_p
m_ListCalPoints.UpdateWind
}
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
You should update scroll info struct depending on your new list control contents..
-MAHESH