Programmatically Scroll A ListView

D

Dave Jackson

Hi All,

I'm trying to programmatically scroll a ListView (I want
to keep two ListViews 'in sync'). I don't seem to be able
to access the ScrollBars through the ListView.Controls, so
I was wondering if there was another way to set ScrollBar
position?

If, as I fear, I need to override the WndProc, I am able
to do this for the majority of the situations, but when a
user clicks and drags the scroll bar (generating an
SB_ThumbTrack or SB_ThumbPosition message) I am unable to
pass those messages along to the second ListView, ro at
least they aren't processing correctly. I'm using
SendMessage in user32.dll. Is there a trick to this that
I'm not getting?

Thanks,
Dave Jackson
 
D

Dave Jackson

Just an adition here. When I override the WndProc and use
SendMessage to send the info along, using Spy++ I can see
that the SB_ThumbPosition and the SB_ThumbTrack messages
are being received by the second ListView, but it's not
processing them for some reason.
 
N

Norman Yuan

You may be able to use ListView.EnsureVisible(int index) method to force
ListView to scroll to a given row.
 
J

Jason Dorie

That wouldn't do what he wants, since the "EnsureVisible" function doesn't
set the scroll position, it just makes sure a specific item is "somewhere"
in the client area.

When handling the ThumbTrack / ThumbPosition messages, why not just
translate them into an absolute scroll position for the 2nd list and use the
SetScrollPos or SetScrollInfo function?

Jason
 
S

SlantyOD

I tried that as well, the problem with that is that it only sets the
position of the scroll bar, and doesn't actually scroll the contents
of the window.

In the end the only solution I could come up with was to put the
ListView in a slightly smaller panel (so the scroll bars aren't
visible) and then add buttons to the form to scroll left, right, up
and down using SB_PageUp, SB_LineUp, etc, which work fine.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top