Article ID: 320425
Article Last Modified on 1/19/2006
APPLIES TO
- Microsoft .NET Framework 1.0
- Microsoft Visual C# .NET 2002 Standard Edition
- Microsoft Visual Basic .NET 2002 Standard Edition
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
- Start Microsoft Visual Studio .NET.
- On the File menu, point to New, and then click Project.
- Click Visual C# Projects or Visual Basic Projects under Project Types, and then click Windows Application under Templates. By default, Form1 is created.
- On the View menu, click Toolbox.
- Drag a ListView control from the toolbox to Form1.
- Drag a Button control from the toolbox to Form1.
- Double-click Button1 to view the code.
Copy the following code in the button1_Click event handler:
Visual C# .NET CodeMessageBox.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")
- On the File menu, click Save.
- On the Debug menu, click Start to run the project.
- 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/library/en-us/vbcon/html/vbconlistviewcontroloverview.asp
Keywords: kbtshoot kbbug kbfix kblistview kbwindowsforms kbwebforms kbctrl kbcontrol kbvs2002sp1sweep kbvs2005swept kbvs2005doesnotapply KB320425