Hi guys,
I have a panel on a form and at runtime I create some controls on the panel. Then, also during runtime I want to clear the panel of all of its controls. The basic way to do this is with the following code:
What happens when I use this code is that only every second control is removed from the panel! Yet, when I replace the .Dispose() method with some other behaviour (like change the control's colour) it appears that every control is accessed correctly. Repeating the code block iteratively removes every second control until none are left, but this is hardly an elegant way to proceed.
So I think this is strange. Can anyone suggest a cause for the problem, or another way of clearing the panel?
Thanks heaps,
Ash
PS: I'm using Visual Studio 2005
I have a panel on a form and at runtime I create some controls on the panel. Then, also during runtime I want to clear the panel of all of its controls. The basic way to do this is with the following code:
Code:
For Each this_ctrl As Object In target_panel.Controls
this_ctrl.Dispose()
Next
So I think this is strange. Can anyone suggest a cause for the problem, or another way of clearing the panel?
Thanks heaps,
Ash
PS: I'm using Visual Studio 2005
Comment