This portion of the application is a simple 'Add/Remove' rows of dynamically added controls. It's transportation software and the user is adding or removing line items to the order. Adding rows is working fine, however i'm now coding the remove portion and ran into this issue below. Each dynamically added control ends with a unique index pertaining to which row of items it belongs to. So the following code, should remove one row of 7 controls, all ending in the same index. However, it only removed about half of them, so i enclosed the FOR EACH in another FOR loop to hit the controls 4 times, AND NOW IT WORKS!?!? Each time i incremented the parent loop to hit the controls again, it removed a couple more, until the magic number 4 removed them all. What could be causing this?
For p As Integer = 1 To 4
For Each c As Control In grpVehicles.Controls
If c.Name.EndsWith(removeIndexClicked) Then
grpVehicles.Controls.Remove(c)
End If
Next
Next