Solved

CListCtrl scrolling problem.

Posted on 2002-04-21
3
1,282 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
mixString challenge 36 98
while loop over for loop 7 79
either24  challenge 19 83
wordappend challenge 8 82
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
This video discusses moving either the default database or any database to a new volume.

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now