Solved

CListCtrl scrolling problem.

Posted on 2002-04-21
3
1,312 Views
Last Modified: 2013-11-20
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
Comment
Question by:yoavo
  • 2
3 Comments
 
LVL 3

Expert Comment

by:GGRUNDY
ID: 6959055
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
 
LVL 49

Accepted Solution

by:
DanRollins earned 50 total points
ID: 6959069
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
 
LVL 49

Expert Comment

by:DanRollins
ID: 6959078
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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.

860 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