views:

289

answers:

3

I'm having some trouble with the Win32 listview, and I hope someone has some wisdom. When scrolling very quickly (via the wheel), occasionally, the listview appears to scroll, only to jump back to the selected item so it is in-view. In other words, the list undoes your wheel scroll to show you the selected item at the top/bottom of the list. I realize this sounds very dubious, as the common controls have been beaten to death the world over.

Here's how you can replicate:

  1. Load up a listview in report mode with about 500 items or so (exact count doesn't matter, you just want several screens of data).
  2. Select an item in the list and remember what you selected.
  3. Rapidly scroll the list with the wheel downwards (toward you). We're trying to scroll the selected item out of view as fast as possible. You probably have to use more force than you usually use on the wheel. This won't always happen. You may have to try several times.
  4. Either the scroll will complete normally, or it will change its mind at the end and pull you back to a view where the selected item is on the screen.

This happens with both regular and virtual listviews. I've tested Win32 and C# on Windows 7 Ultimate.

I made a small WinForms app that exhibits the behavior (requires .NET Framework 3.5). If you'd rather not run arbitrary executables from strangers (I understand), make a new WinForms app, drop a listview in report mode in, add a column, and populate the list in the form load event with 500 increasing integers:

private void Form1_Load(object sender, EventArgs e)
{
    for (int i = 0; i < 500; i++)
    {
        this.listView1.Items.Add(i.ToString());
    }
}
A: 

"I realize this sounds very dubious, as the common controls have been beaten to death the world over."

ListView hasn't quite been beaten to death but it's on life support. Use a different control.

Windows programmer
This is fine if I find a replacement. Do you have any suggestions for an open-source license-compatible ListView that can handle virtual lists? CodeProject didn't have much of interest.
Matt Green
Back in the days of VC++ 6 I used a FlexGrid for something. Microsoft designed it for VB but it was usable from VC++. .Net has a DataGrid, which I haven't tried, but it might help you.
Windows programmer
FlexGrid looks good, but also way out of date. I think I will stick with the stock control for now and keep looking for a replacement. If all else fails, I will start working on my own. :)
Matt Green
+1  A: 

I've noticed this behavior and it does seem to be built into the list view control. I can't see any reason why the functionality would be useful. I created a thread on this at Sysinternals Forums a while back. It might be useful.

wj32
Sounds like a job for Raymond Chen.Interestingly, the issue appears not to manifest in 7's Explorer. It does show up in XP, however. A quick check at Spy++ shows the listbox's window class to be named DirectUIHWND, so they may be subclassing it and doing things to block it.
Matt Green
Lots of kinds of windows use the DirectUIHWND class.
Windows programmer
A: 

is it a custom list view (overriding drawing ?) by the way, I faced (from what I understand) the same issue with a custom Listbox and found some help here :

http://aviationxchange.net/wikis/winforms/net-color-listbox.aspx (end of the document).

Hope this could help.

camous