tags:

views:

466

answers:

2

How can I make a WinForms ListView scroll vertical by MouseWheel?

I'm using C#.

A: 

This is a duplicate of http://stackoverflow.com/questions/87134/c-listview-mouse-wheel-scroll-without-focus

AlbertEin
you need such a low level construct for scrolling a listview by mousewheel? damn...
Kai
A: 

Is it OK if the list scrolls only when it has focus? If so, use the Control.MouseWheel event.

Do you want the list to scroll if it doesn't have focus? Then you need to need to either implement a mouse hook, as described in the other article, or take a look at the Application.AddMessageFilter method. Application.AddMessageFilter gives you a managed version of a mouse hook. You get to preview the messages as they come in. I wrote something about it here.

Paul Williams
I just want to scroll it if it has focus
Kai
OK, then MouseWheel should work. Override MouseWheel. Figure out which way to scroll (down for positive delta, I think?), take the current selected index, add a known value to it, and call ListView.EnsureVisible(newIndex).
Paul Williams
Err, when I say "known value", come up with a rule like "wheel down = 4 rows", and call EnsureVisible(listView.SelectedIndex + 4) on the new index, but don't forget to limit the bounds of the new index.
Paul Williams
I'll have a try and post back later
Kai