Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
535
Error enum'ing UltraListView: "collection was modified; enumeration operation might not execute".
posted

Getting this error when SETTING checkboxes in an Infragistics.Win.UltraWinListView.UltraListView

"collection was modified; enumeration operation might not execute".

I Googled "collection was modified; enumeration operation might not execute" and came up with

lots of advice to avoid this error when deletes are being done to the enum, advice not to use enum, etc.

BUT . . . I'm getting the error when I'M NOT removing anything from OR  modifiying the enum in anyway,

except that boxes are being checked. Please advise.

code:

===================================================================================

With Me.ModelTypeUltraListView

    .Items.SetCheckState(CheckState.Unchecked)

    For Each row As CommonalitiesDataSet.CommonalityModelTypesRow In Me.CommonalitiesDataSet.CommonalityModelTypes        

        .Items(CStr(row("ModelTypeID"))).CheckState = CheckState.Checked

    Next

End With

================================================================================== 

There are 5 UltraListView on this form/control.

If I rearrange the snippets for each of the 5 ULV's the error will occur on a different 1 of the 5, but the same error.

AND the error appears to be coming from the DataSet.DataTable enum . . . on the Next statement.

If I do something like

==========================================================================

Me.CountryUltraListView.Items.SetCheckState(CheckState.Unchecked)

For Each row As CommonalitiesDataSet.CommonalityCountriesRow In Me.CommonalitiesDataSet.CommonalityCountries

    i += 1

    str = CStr(row("CountryID"))

    'Me.CountryUltraListView.Items(str).CheckState = CheckState.Checked

Next

==========================================================================

I can iterate thru the DataTable just fine . . . . and there are 5 rows in Me.CommonalitiesDataSet.CommonalityCountries

AS SOON as I un-comment the

'Me.CountryUltraListView.Items(str).CheckState = CheckState.Checked

the error occurs on the

Next

on only the 2nd time thru the loop ??????

===============================================

System.InvalidOperationException was caught
  Message="Collection was modified; enumeration operation might not execute."
  Source="System.Data"
  StackTrace:
       at System.Data.RBTree`1.RBTreeEnumerator.MoveNext()

===============================================

Thx,

XPXJ

 

  • 469350
    Verified Answer
    Offline posted
    The error you are getting isn't from the ListView, it looks like it's in the data source. Perhaps you are hooking an event either on your DataSet or the ListView and that event handler is firing when the CheckState of the ListView is changing and modifying the data while the loop is running?