Search code examples
winapilistviewgridlines

Listview gridlines issue


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!


Solution

  • 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.