Microsoft KB Archive/320425

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

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.



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.</li> Double-click Button1 to view the code.</li>  Copy the following code in the button1_Click event handler:

Visual C# .NET Code MessageBox.Show(&quot;Fill the list&quot;); listView1.BeginUpdate; for(int i=0; i<20000; i++) {   ListViewItem item=new ListViewItem(new string[]{&quot;Hello&quot;, &quot;World&quot; }); listView1.Items.Add(item); } listView1.EndUpdate; MessageBox.Show(&quot;Remove some entries&quot;); listView1.Items.RemoveAt(1); listView1.Items.RemoveAt(2); MessageBox.Show(&quot;Invoking Clear Method&quot;); listView1.Clear; MessageBox.Show(&quot;Clear Method Completed&quot;);

MessageBox.Show(&quot;Fill the List again&quot;);

listView1.BeginUpdate; for(int i=0;i<20000;i++) {   ListViewItem item=new ListViewItem(new string[]{&quot;Hello&quot;,&quot;World&quot;}); listView1.Items.Add(item); } listView1.EndUpdate; MessageBox.Show(&quot;Remove some entries&quot;); listView1.Items.RemoveAt(1); listView1.Items.RemoveAt(2); MessageBox.Show(&quot;Invoking Dispose Method&quot;); listView1.Dispose; MessageBox.Show(&quot;Dispose Method Completed&quot;); Visual Basic .NET Code MessageBox.Show(&quot;Fill the list&quot;) ListView1.BeginUpdate Dim idx As Integer For idx = 0 To 20000 Dim item As ListViewItem = New ListViewItem(New String {&quot;Hello&quot;, &quot;World&quot;}) ListView1.Items.Add(item) Next ListView1.EndUpdate MessageBox.Show(&quot;Remove some entries&quot;) ListView1.Items.RemoveAt(1) ListView1.Items.RemoveAt(2) MessageBox.Show(&quot;Invoking Clear Method&quot;) ListView1.Clear MessageBox.Show(&quot;Clear Method completed&quot;) MessageBox.Show(&quot;Re Fill the list&quot;) ListView1.BeginUpdate Dim idx1 As Integer For idx1 = 0 To 20000 Dim item As ListViewItem = New ListViewItem(New String {&quot;Hello&quot;, &quot;World&quot;}) ListView1.Items.Add(item) Next ListView1.EndUpdate

MessageBox.Show(&quot;Remove some entries&quot;) ListView1.Items.RemoveAt(1) ListView1.Items.RemoveAt(2)

MessageBox.Show(&quot;Invoking Dispose Method&quot;) ListView1.Dispose MessageBox.Show(&quot;Dispose Method completed&quot;) </li> On the File menu, click Save.</li> On the Debug menu, click Start to run the project.</li> Click Button1.</li></ol>

<div class="references_section">