Collection was modified; enumeration operation may not execute.
Certain collections blow out when you use a for each loop, as the change in value results in the item dropping out of the collection.
This code resulted in the above error as it caused the CheckNodes collection to change.
For Each node As TreeNode In TreeView1.CheckedNodes
node.Checked = False
Next
Re-writing the code as so works fine:
Dim y As Integer = TreeView1.CheckedNodes.Count
While y > 0
TreeView1.CheckedNodes.Item(0).Checked = False
y -= 1
End While
Trackback URI |