You are currently offline, waiting for your internet to reconnect

FIX: Delay in response for Dispose or Clear methods of a ListView control in Visual Studio .NET 2002

This article was previously published under Q320425
This article has been archived. It is offered "as is" and will no longer be updated.
When you remove some ListView items from the ListView control and then invoke the Dispose or the Clear method, you experience a slow response time.
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. This bug was corrected in Microsoft Visual Studio .NET 2003.

Steps to Reproduce the Behavior

  1. Start Microsoft Visual Studio .NET.
  2. On the File menu, point to New, and then click Project.
  3. Click Visual C# Projects or Visual Basic Projects under Project Types, and then click Windows Application under Templates. By default, Form1 is created.
  4. On the View menu, click Toolbox.
  5. Drag a ListView control from the toolbox to Form1.
  6. Drag a Button control from the toolbox to Form1.
  7. Double-click Button1 to view the code.
  8. Copy the following code in the button1_Click event handler:

    Visual C# .NET Code
    MessageBox.Show("Fill the list");listView1.BeginUpdate();for(int i=0; i<20000; i++){    ListViewItem item=new ListViewItem(new string[]{"Hello" , "World" });    listView1.Items.Add(item);}listView1.EndUpdate();MessageBox.Show("Remove some entries");listView1.Items.RemoveAt(1);listView1.Items.RemoveAt(2);MessageBox.Show("Invoking Clear Method");listView1.Clear();MessageBox.Show("Clear Method Completed");MessageBox.Show("Fill the List again");listView1.BeginUpdate();for(int i=0;i<20000;i++){    ListViewItem item=new ListViewItem(new string[]{"Hello","World"});    listView1.Items.Add(item);}listView1.EndUpdate();MessageBox.Show("Remove some entries");listView1.Items.RemoveAt(1);listView1.Items.RemoveAt(2);MessageBox.Show("Invoking Dispose Method");listView1.Dispose();MessageBox.Show("Dispose Method Completed");	
    Visual Basic .NET Code
    MessageBox.Show("Fill the list")ListView1.BeginUpdate()Dim idx As IntegerFor idx = 0 To 20000    Dim item As ListViewItem = New ListViewItem(New String() {"Hello", "World"})    ListView1.Items.Add(item)NextListView1.EndUpdate()MessageBox.Show("Remove some entries")ListView1.Items.RemoveAt(1)ListView1.Items.RemoveAt(2)MessageBox.Show("Invoking Clear Method")ListView1.Clear()MessageBox.Show("Clear Method completed")MessageBox.Show("Re Fill the list")ListView1.BeginUpdate()Dim idx1 As IntegerFor idx1 = 0 To 20000     Dim item As ListViewItem = New ListViewItem(New String() {"Hello", "World"})     ListView1.Items.Add(item) Next ListView1.EndUpdate() MessageBox.Show("Remove some entries") ListView1.Items.RemoveAt(1) ListView1.Items.RemoveAt(2) MessageBox.Show("Invoking Dispose Method") ListView1.Dispose() MessageBox.Show("Dispose Method completed")
  9. On the File menu, click Save.
  10. On the Debug menu, click Start to run the project.
  11. Click Button1.
For more information about the ListView control, visit the following Microsoft Developer Network (MSDN) Web site:
Introduction to the Windows Forms ListView Control

Article ID: 320425 - Last Review: 10/24/2013 11:12:54 - Revision: 1.4

Microsoft .NET Framework 1.0, Microsoft Visual C# .NET 2002 Standard Edition, Microsoft Visual Basic .NET 2002 Standard Edition

  • kbnosurvey kbarchive kbvs2005doesnotapply kbvs2005swept kbtshoot kbvs2002sp1sweep kbwindowsforms kbcontrol kbctrl kbbug kbfix kblistview kbwebforms KB320425