froodley
Active member
- Joined
- Apr 20, 2010
- Messages
- 26
- Programming Experience
- 1-3
Hi, all,
I have a databound listbox. I was refreshing the binding, then using this code:
For Each i As Object In this_lb.Items
If CType(i, ClassA) = currentSelection Then
this_lb.SelectedItem = i
End If
Next
...to restore the current selection, but this is failing (on the assignment, selecteditem = i) if I have changed the underlying data source for the list box, even thought I am refreshing its currency manager before the enumerator:
CType(thisCtrl.BindingContext(thisCtrl.DataSource), CurrencyManager).Refresh()
It's giving me the "enumerator failed because underlying ienumerable changed" error.
If I do the same thing this way:
For i = 0 To this_lb.Items.Count - 1
If CType(this_lb.Items(i), ClassA) = currentSelection Then
this_lbTests.SelectedIndex = i
End If
Next
... it works fine in the same scenario. What's going on here? What's changing the list? There's no threading here...
I have a databound listbox. I was refreshing the binding, then using this code:
For Each i As Object In this_lb.Items
If CType(i, ClassA) = currentSelection Then
this_lb.SelectedItem = i
End If
Next
...to restore the current selection, but this is failing (on the assignment, selecteditem = i) if I have changed the underlying data source for the list box, even thought I am refreshing its currency manager before the enumerator:
CType(thisCtrl.BindingContext(thisCtrl.DataSource), CurrencyManager).Refresh()
It's giving me the "enumerator failed because underlying ienumerable changed" error.
If I do the same thing this way:
For i = 0 To this_lb.Items.Count - 1
If CType(this_lb.Items(i), ClassA) = currentSelection Then
this_lbTests.SelectedIndex = i
End If
Next
... it works fine in the same scenario. What's going on here? What's changing the list? There's no threading here...