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

Article translations Article translations
Article ID: 320425 - View products that this article applies to.
This article was previously published under Q320425
This article has been archived. It is offered "as is" and will no longer be updated.
Expand all | Collapse all

On This Page

SYMPTOMS

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.

STATUS

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.

MORE INFORMATION

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 Integer
    For idx = 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 Clear Method")
    ListView1.Clear()
    MessageBox.Show("Clear Method completed")
    MessageBox.Show("Re Fill the list")
    ListView1.BeginUpdate()
    Dim idx1 As Integer
    For 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.

REFERENCES

For more information about the ListView control, visit the following Microsoft Developer Network (MSDN) Web site:
Introduction to the Windows Forms ListView Control
http://msdn.microsoft.com/en-us/library/aa983663.aspx

Properties

Article ID: 320425 - Last Review: October 24, 2013 - Revision: 1.4
APPLIES TO
  • Microsoft .NET Framework 1.0
  • Microsoft Visual C# .NET 2002 Standard Edition
  • Microsoft Visual Basic .NET 2002 Standard Edition
Keywords: 
kbnosurvey kbarchive kbvs2005doesnotapply kbvs2005swept kbtshoot kbvs2002sp1sweep kbwindowsforms kbcontrol kbctrl kbbug kbfix kblistview kbwebforms KB320425

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com