Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete Newly added row from dataset

Status
Not open for further replies.

asmith555

Programmer
Oct 7, 2002
97
US
I have an app which has a datagrid in which you can add and delete items.

After an Item is added the dataset is updated and rebound to the grid.

If I try to delete the newly added item I get this Error:
Collection was modified; enumeration operation may not execute

This error occurs when I run a for each loop through the Datatable's row collection.

Is this not allowed. What can I do about it?
 
The foreach loop will fail if the collection it is looping through is modified.

Try finding the row and calling DataRow.Delete.
 
The collection is not modified in the loop. It is modified before the foreach begins. Does that make a difference?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top