I have a listbox that has x amount of object loaded from a txt file with this code:
Dim lines() As String = IO.File.ReadAllLines(Application.StartupPath() + "\file.txt") List.Items.AddRange(lines) Try List.SelectedIndex = 0 Catch ex As Exception End Try Return True It loads them fine. Then I only try to loop through them like this:
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click Dim num As Integer = 0 Dim item As Object For Each item In List.Items List.SelectedIndex = num num += 1 Next End Sub The error I get is this:
An unhandled exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll
Additional information: List that this enumerator is bound to has been modified. An enumerator can only be used if the list does not change.
I tried to load the listbox manually, didn't help. Any help here?