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



The information in this article applies to:

  • Microsoft .NET Framework 1.0
  • Microsoft Visual C# .NET (2002)
  • Microsoft Visual Basic .NET (2002)

This article was previously published under Q320425

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:

Modification Type:MinorLast Reviewed:1/19/2006
Keywords:kbvs2005doesnotapply kbvs2005swept kbtshoot kbvs2002sp1sweep kbWindowsForms kbControl kbCtrl kbbug kbfix kbListView kbWebForms KB320425 kbAudDeveloper