Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 690
  • Last Modified:

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
0
jhorstkamp
Asked:
jhorstkamp
  • 2
  • 2
1 Solution
 
mahesh1402Commented:
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
0
 
jhorstkampAuthor Commented:
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


0
 
mahesh1402Commented:
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

-MAHESH
0
 
jhorstkampAuthor Commented:
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



0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now