[Mono-bugs] [Bug 425342] New: ListView: Remove Item while enumerating

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Wed Sep 10 21:27:50 EDT 2008


https://bugzilla.novell.com/show_bug.cgi?id=425342


           Summary: ListView: Remove Item while enumerating
           Product: Mono: Class Libraries
           Version: 2.0
          Platform: i386
        OS/Version: All
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: Windows.Forms
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: johnm at hlaustralia.com.au
         QAContact: mono-bugs at lists.ximian.com
          Found By: DeveloperNet


Description of Problem:

If you are enumerating through the ListView.Items collection and remove an
item, the next iteration will result in a System.InvalidOperationException

Steps to reproduce the problem:

using System;
using System.Windows.Forms;

public class test
{
        static void Main ()
        {
                Form f = new Form ();

                        ListView lv = new ListView();
                        for (int i = 0; i < 20; i++)
                        {
                            ListViewItem item = lv.Items.Add("Item");
                            if (i % 2 == 0)
                                item.Tag = "DELETEME";
                            else
                                item.Tag = String.Empty;
                        }

                        foreach (ListViewItem item in lv.Items)
                        {
                            if (item.Tag.Equals("DELETEME"))
                            {
                                lv.Items.Remove(item);
                            }
                        }
                        Console.Write(String.Format("Items = {0}, Expected=10",
lv.Items.Count));

                lv.Parent = f;

                Application.Run (f);
        }
}


Actual Results:
Exception is raised.


Expected Results:
The Item is Deleted (this works in MS.NET, Visual Studio 2005) and the
iteration takes you to the next item.

How often does this happen? 
Every Time.


Additional Information:


-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list