?
Solved

CListCtrl scrolling problem.

Posted on 2002-04-21
3
Medium Priority
?
1,333 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 200 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

Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

Question has a verified solution.

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

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: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

777 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