4

There's a problem with drawing gridlines in listview with common controls 6. It happens when I try to scroll the list page down or page up with mouse.

screenshot
(source: rsdn.ru) .

I was only able to find this discussion http://www.ureader.com/msg/1484143.aspx, but the solutions are not perfect

  1. LVS_EX_DOUBLEBUFFER doesn't work for me
  2. Disabling smooth scrolling doesn't work for me
  3. Invalidate on scroll does work but the flicker is not fine
  4. Disabling grid lines does work but the list doesn't look fine without them.

Are there any other options? Thanks!

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Fedor
  • 43,261
  • 10
  • 79
  • 89
  • This is probably not really an option, but what about *not* relying on 6-year old technology? – MusiGenesis Sep 13 '09 at 03:57
  • 1
    Even if I use .NET and WinForms I'll experience the same problem because WinForms rely on WinApi and uses the same Listview as I do. And you're right, it's not an option. I'm not going to rewrite the whole software. I just need to fix the issue. – Fedor Sep 13 '09 at 14:09

5 Answers5

2

ObjectListView -- a open source wrapper around a plain .NET WinForms ListView -- fixes this problem (and lots of others too).

If you want to fix it in your own code, you need to listen for reflected notification of LVN_ENDSCROLL. In the handler for the end scroll, do something like this:

protected void HandleEndScroll(ref Message m) {
    // There is a bug in ListView under XP that causes the gridlines to be 
    // incorrectly scrolled when the left button is clicked to scroll. 
    // This is supposedly documented at KB 813791, but I couldn't find it. 
    if (!ObjectListView.IsVista && 
        Control.MouseButtons == MouseButtons.Left &&
        this.GridLines) {
        this.Invalidate();
        this.Update();
    }
}

There is a slight flicker with this, but it's much better than having the grid lines completely messed up.

Grammarian
  • 6,774
  • 1
  • 18
  • 32
1

I chose to subclass listview and process WM_VSCROLL message:

  WORD x=LOWORD(wParam);
  if(iMsg==WM_VSCROLL && (x==SB_PAGEDOWN || x==SB_PAGEUP || x==SB_LINEDOWN || x==SB_LINEUP))
  {
    InvalidateRect(hDlg, 0, true);
    UpdateWindow(hDlg);
  }
Fedor
  • 43,261
  • 10
  • 79
  • 89
  • 1
    The advantage of using LVN_ENDSCROLL is that it is sent whenever the listview scrolls (well, mostly). WM_VSCROLL is only sent when the scrollbar is manipulated. Using the mouse wheel to scroll will send LVN_ENDSCROLL, but not WM_VSCROLL. BUT this problem only happens when the mouse is clicked, so using the WM_VSCROLL message works fine too. – Grammarian Sep 15 '09 at 07:31
0

It's a Win32 Usenet FAQ since 2001, see Google Groups : Win32 Listview , C code (MS)

0

I have a project converted from VB6 to MS Vs2005, which has the same issue when I enable the "Enable XP visual style" from project properties -> Application setting. Then I disable the feature, and it fix the problem.

Yan
  • 1
0

Cant you just invalidate the control and have it redraw when it the user is done scrolling? I dont remember exactly how to do this, but I have had a similar problem before, and thats how I handled it.

Shaun
  • 5,483
  • 10
  • 40
  • 49