I'm using ListView in VirtualMode and Details View with small icons.
This ListView have like 100,000 items inside.
The problem is that drawing this listview is much slower in Windows 7 compared to XP.
You can fill the slow drawing while scrolling the ListView or while multi-selecting items.
Additionally, i noticed that drawing become slower with each column added.
RetrieveVirtualItem event handler for now doing nothing but return literal values, so this is not the bottleneck.
Any ideas?
UPDATE: Source code for reproduce:
FlickerFreeListView.cs:
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.Drawing;
using System.Reflection;
using System.Diagnostics;
namespace ListViewTest
{
public class FlickerFreeListView : ListView
{
public FlickerFreeListView()
{
base.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
}
}
}
Form1.cs:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace ListViewTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
_item = new ListViewItem(new string[6]);
}
private ListViewItem _item;
private void listView1_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e)
{
string itemIndexStr = e.ItemIndex.ToString();
_item.Text = itemIndexStr;
_item.SubItems[1].Text = "blablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablabla";
_item.SubItems[2].Text = itemIndexStr;
_item.SubItems[3].Text = itemIndexStr;
_item.SubItems[4].Text = itemIndexStr;
_item.SubItems[5].Text = itemIndexStr;
e.Item = _item;
}
}
}
Form1.Designer.cs:
namespace ListViewTest
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.listView1 = new ListViewTest.FlickerFreeListView();
this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
this.columnHeader3 = new System.Windows.Forms.ColumnHeader();
this.columnHeader4 = new System.Windows.Forms.ColumnHeader();
this.columnHeader5 = new System.Windows.Forms.ColumnHeader();
this.columnHeader6 = new System.Windows.Forms.ColumnHeader();
this.SuspendLayout();
//
// listView1
//
this.listView1.AutoArrange = false;
this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader1,
this.columnHeader2,
this.columnHeader3,
this.columnHeader4,
this.columnHeader5,
this.columnHeader6});
this.listView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.listView1.FullRowSelect = true;
this.listView1.HideSelection = false;
this.listView1.Location = new System.Drawing.Point(0, 0);
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(1032, 388);
this.listView1.TabIndex = 0;
this.listView1.UseCompatibleStateImageBehavior = false;
this.listView1.View = System.Windows.Forms.View.Details;
this.listView1.VirtualListSize = 100000;
this.listView1.VirtualMode = true;
this.listView1.RetrieveVirtualItem += new System.Windows.Forms.RetrieveVirtualItemEventHandler(this.listView1_RetrieveVirtualItem);
//
// columnHeader1
//
this.columnHeader1.Width = 92;
//
// columnHeader2
//
this.columnHeader2.Width = 405;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1032, 388);
this.Controls.Add(this.listView1);
this.Name = "Form1";
this.Text = "Form1";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.ResumeLayout(false);
}
#endregion
private FlickerFreeListView listView1;
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.ColumnHeader columnHeader2;
private System.Windows.Forms.ColumnHeader columnHeader3;
private System.Windows.Forms.ColumnHeader columnHeader4;
private System.Windows.Forms.ColumnHeader columnHeader5;
private System.Windows.Forms.ColumnHeader columnHeader6;
}
}