Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Collection was modified: enumeration operation may (Read 3989 times)
elpuerco
Junior Member
**
Offline


Time?  What's time matta
to a pig?

Posts: 94
Joined: Oct 2nd, 2007
Collection was modified: enumeration operation may
Dec 18th, 2007 at 2:40pm
Print Post  
I had a search for this error and only came up with this thread which does not help me on this instance, although as my application will be multi user the delegate snippet will be useful to test.

http://mindfusion.org/cgi/Forum/YaBB.pl?action=search2

However, following on from the grouping by locations I find I have another problem.

I have two calendars, one in month view and the other in time table view.

calmonth is linked to caltime so every time a user amends caltime the highlighting is updated accordingly on calmonth.

All works great except when I change location I get the error listed in thread subject on this code:

Code
Select All
  For Each s In Me.calMonthView.DayStyles

			  Me.calMonthView.DayStyles.Remove(s)

 Next
 



This code is used in a different place in response to users deleting and appintment and is in an if statement which tests the day/time and removes is required and works ok.

I have not restricted to a day/time as it needs to clear the entire style so that when moving from one location to the other the previous locations styles are cleared before the new locations styles are drawn.

I hope I make sense?

Thanks

  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Collection was modified: enumeration operation
Reply #1 - Dec 19th, 2007 at 6:19am
Print Post  
You have to either stop the loop immediately once the collection is modified or (if you need to delete more than one object from the collection) you have to do this in an ordinary For loop. Otherwise, the enumerator throws an exception if its underlying collection was modified.

Meppy
  
Back to top
 
IP Logged
 
elpuerco
Junior Member
**
Offline


Time?  What's time matta
to a pig?

Posts: 94
Joined: Oct 2nd, 2007
Re: Collection was modified: enumeration operation
Reply #2 - Dec 19th, 2007 at 10:35am
Print Post  
Is this something specific to Planner.NET?  I thought if I cycled thru the collection it would only process those that were found in it?

However when I try it this way:

Code
Select All
 For x = 0 To Me.calMonthView.DayStyles.Count - 1

	 Me.calMonthView.DayStyles.RemoveAt(x)

 Next
 



I do not get the error which is good but the highlight does not get removed?



  
Back to top
 
IP Logged
 
elpuerco
Junior Member
**
Offline


Time?  What's time matta
to a pig?

Posts: 94
Joined: Oct 2nd, 2007
Re: Collection was modified: enumeration operation
Reply #3 - Dec 19th, 2007 at 10:55am
Print Post  
I also try this with no results:

Code
Select All
 For x = 0 To Me.calMonthView.DayStyles.Count - 1

     s = Me.calMonthView.DayStyles(x)

     Me.calMonthView.DayStyles.Remove(s)

 Next
 



I see in the Planner.NET help that RemoveAt is not listed?
  
Back to top
 
IP Logged
 
elpuerco
Junior Member
**
Offline


Time?  What's time matta
to a pig?

Posts: 94
Joined: Oct 2nd, 2007
Re: Collection was modified: enumeration operation
Reply #4 - Dec 19th, 2007 at 12:05pm
Print Post  
OK I have now tracked it down to this bit of code!

The RemoveAt works a treat, however the code below redraws the highlight.

Code
Select All
Me.calTimeTableView.LoadFromDataSource()

' clear the calendar locations

Me.calTimeTableView.Locations.Clear()

' add the location chosen by user on form

Me.calTimeTableView.Locations.Add(Me.calTimeTableView.Schedule.Locations(intBuilding))

' and set calendar to group by location

Me.calTimeTableView.GroupType = GroupType.GroupByLocations

' cycle through timetableview items in order to update monthview highlighting

For Each itemMonth In Me.calTimeTableView.Schedule.Items

    ' for every item in the timetableview process it into the monthview

	ProcessItemCreated(itemMonth)

 Next
 



So my confusion is this...

If I have grouped by location and the user has selected location 2 why does the code above process all locations 1 and 2?

I can see I am obviuosly not graspng the full functionality of the Planner control!


  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Collection was modified: enumeration operation
Reply #5 - Dec 19th, 2007 at 12:18pm
Print Post  
The Schedule.Items collection contains all items regardless of whether they are displayed in the calendar or not. If you are interested in processing only the items matching certain criteria (only those that are associated with a particular location in your case), you have to do this manually. Simply add a condition before processing an item, which tests whether the item is associated with the appropriate location.

Meppy
  
Back to top
 
IP Logged
 
elpuerco
Junior Member
**
Offline


Time?  What's time matta
to a pig?

Posts: 94
Joined: Oct 2nd, 2007
Re: Collection was modified: enumeration operation
Reply #6 - Dec 19th, 2007 at 1:03pm
Print Post  
Yep, I was on to that before I came back to read your post  Grin

Here is the working result:

Code
Select All
 For Each itemMonth In Me.calTimeTableView.Schedule.Items

   Select Case intBuilding

	Case 0

	     If itemMonth.Location.Name = "WHSE1" Then

			   ProcessItemCreated(itemMonth)

	     End If

	 Case 1

		If itemMonth.Location.Name = "WHSE2" Then

			   ProcessItemCreated(itemMonth)

		End If

	  End Select

Next
 



Grin Grin
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint