I have been working on a little project and basically it is a parent form that has a child from with Tab Controls inside. When i change tab it adds the relevant options for that tab to the parents menu strip.
What i would like to do is, instead of every time i change tab a new 'Options' appears on the menu strip, so after a few tab changes it has 'Options' 'Options' 'Options' 'Options' on the menu strip, but i would rather remove the options from the previous tab and only have the 1 options displayed.
The code i have so far to remove the options before adding new ones is as follow:
Dim ParentForm As frmNavigation = frmNavigation
Dim OptionsMenuStrip As MenuStrip = ParentForm.Controls("MenuStrip1")
Dim Items As ToolStripItemCollection = OptionsMenuStrip.Items
For Each Item As ToolStripMenuItem In Items
If Item.Name = "OptionsMenu" Then
Item.Dispose()
End If
Next
But i am getting the error
'Collection was modified; enumeration operation may not execute.'
Which I understand is basically it saying the collections changing it whilst it's being read, I think?
I just don't know a way around it
Any help to achieve what i want would be greatly appreciated.
I may even be going totally the wrong way about it but i feel so close!
Thanks you :)