Experts this is really baffling me. I have a visual studio 2008 windows form. When the form loads I dynamically build 17 panels, I also add controls to those same panels, finally I add those panels to a flow layout panel. The reasoning behind this, is the 17 panels represents a 1 record in our database, I will not know the details of the panel until the query is ran. When the record is completed via database side I need to remove those 17 panels and eventually build 17 more panels. If you look at the code below I thought i could just loop through all the controls in the panel and dispose them. This is not the case not all the controls get disposed. When I click the button only 9 get disposed, then the second click 4 get disposed, then 2, then 1, then 1. Totalling 17 controls in all. I need to click the button 5 times to completely dispose all the controls, why is this and how come the don't get diposed the first time through? If you need the code showing how I dynamically build the panels let me know.
Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
clear_controls(Me.flpbase) 'Flow layout panel containing controls I want to dispose
Sub clear_controls(ByVal ctrl As Control)
Dim frmctrl As Control
For Each frmctrl In ctrl.Controls