• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1345
  • Last Modified:

CListCtrl scrolling problem.

Hi,
I have a list control with a vertical scrollbar. I have implemented a sort function which removes all the items from the list and insert them in the new order.
After the sort operation the vertical scroll bar is placed at the top.
My problem is that I want to keep the old position of the scroll bar (before the sort operation).
I tried using GetTopIndex before the sort, but I couldnt find a way to restore this information after the sort operation...

Yoav.
0
yoavo
Asked:
yoavo
  • 2
1 Solution
 
GGRUNDYCommented:
Does SetTopIndex not do what you want?
Maybe you need to SetTopIndex to the Max (ie scroll right to the bottom) before you SetTopIndex to what you really want.
0
 
DanRollinsCommented:
It's probably easiest to call EnsureVisible( nItem ).  That does not guarantee that the list will scroll to the desired line, but it will usually be pretty close.

You can use Scroll( cs ) where cs is a CSize item that describes how far to scroll.  You can figure out how far to scroll by multiplying the height of one item by the original position.  You can learn the height of one item by usie the GetItemRect() function.

Incidently, if an item is already selected, you may be better off selecting it and scrolling it into view via EnsureVisible() rather than scrolling the whole list to some arbitrary location.  After all, the user probably wants to see that item since he selected it.

-- Dan
0
 
DanRollinsCommented:
Hi GGRUNDY,
I don't see a SetTopIndex member for CListCtrl nor is there a similar message for the Win32 API access to the ListView control that it wraps.  Perhaps you are confused with CListBox...
-- Dan
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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