Thanks so much for your help Seth !
I placed the code below into the project... odd thing though...
It appears to delete only half the controls... (FYI - using 2.0 VS2005)
I have a button that adds user controls to the FlowLayoutPanel... so I added
8 of them... ran the code and 4 were deleted... ran again... 2 more were
deleted...
Public Sub Wipeout(ByVal c As Control)
If (Me.FlowLayoutPanel1.Controls.Contains(c)) Then
Me.FlowLayoutPanel1.Controls.Remove(c)
c.Dispose()
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
Dim strControlName As String
For Each c As Control In Me.FlowLayoutPanel1.Controls
strControlName = c.Name
If (c.Name = strControlName) Then
Wipeout(c)
'Exit For
End If
Next
End Sub
- Rob
I tried this...
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
Dim delme As Object
delme = New Object()
Dim ctrl As Control
For Each ctrl In FlowLayoutPanel1.Controls
delme = (ctrl.Name)
Call wipeout(delme)
Next
End Sub
End Class
Public Sub wipeout(ByRef delme As Object)
Me.FlowLayoutPanel1.Controls.Remove(delme)
End Sub
Try something like this:
' Typed in message
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
For Each c As Control In Me.FlowLayoutPanel1.Controls
If (c.Name = "The name of the control to delete") Then
Wipeout(c)
Exit For
End If
Next
End Class
Public Sub Wipeout(ByVal c as Control)
If (Me.FlowLayoutPanel1.Controls.Contains(c)) Then
Me.FlowLayoutPanel1.Controls.Remove(c)
c.Dispose()
End If
End Sub
Or if you're using .Net 2.0 (VB 2005) you should be able to do this:
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
Wipeout(Me.FlowLayoutPanel1.FindControl("The name of the control
to delete"))
End Class
Public Sub Wipeout(ByVal c as Control)
If (Me.FlowLayoutPanel1.Controls.Contains(c)) Then
Me.FlowLayoutPanel1.Controls.Remove(c)
c.Dispose()
End If
End Sub
Thanks,
Seth Rowe