Re: listBox.Items.Remove help
From: Matt Berther (mberther_at_hotmail.com)
Date: 04/23/04
- Next message: John Doe: "Problem in Zero Deployement"
- Previous message: Chris Adams: "Listview Item.Selected not populating Listview.SelectedItems collection"
- In reply to: Bilo: "listBox.Items.Remove help"
- Next in thread: Bilo: "Re: listBox.Items.Remove help"
- Reply: Bilo: "Re: listBox.Items.Remove help"
- Reply: Palo Mraz: "Re: listBox.Items.Remove help"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 22 Apr 2004 17:42:00 -0700
Hello Bilo,
> 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.Mo
> veNext
> ()
You can't modify a collection if you are iterating it with an Enumerator.
It appears to me that this line may suffice for what you're trying to accomplish.
listBox1.Items.Clear();
-- Matt Berther http://www.mattberther.com
- Next message: John Doe: "Problem in Zero Deployement"
- Previous message: Chris Adams: "Listview Item.Selected not populating Listview.SelectedItems collection"
- In reply to: Bilo: "listBox.Items.Remove help"
- Next in thread: Bilo: "Re: listBox.Items.Remove help"
- Reply: Bilo: "Re: listBox.Items.Remove help"
- Reply: Palo Mraz: "Re: listBox.Items.Remove help"
- Messages sorted by: [ date ] [ thread ]