Solved

CListCtrl scrolling problem.

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Pressing cancel button with C# UI Automation 3 51
Expand macro to ask for filename column 8 37
either24  challenge 19 90
ShiftLeft challenge 21 76
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

895 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

17 Experts available now in Live!

Get 1:1 Help Now