listBox1.Items.Remove help

From: Bilo (justler123_at_yahoo.com)
Date: 04/22/04


Date: Fri, 23 Apr 2004 01:34:23 +0200

I dont know what i am doing false.
the code :

private void button2_Click(object sender, System.EventArgs e)
{
        foreach (string filename in listBox1.SelectedItems)
        listBox1.Items.Remove(filename);
}
gives me the error :

System.InvalidOperationException: The list that this enumerator is bound to
has been modified. An enumerator can only be used if the list doesn't
change.
 at
System.Windows.Forms.EntryEnumerator.System.Collections.IEnumerator.MoveNext
()

Anyone can help?