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
"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:11**********************@y80g2000hsf.googlegr oups.com...
On May 12, 7:15 am, "Rob" <r...@yahoo.comwrote:
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
"Mattias Sjögren" <mattias.dont.want.s...@mvps.orgwrote in message
news:ed**************@TK2MSFTNGP05.phx.gbl...
>How may I pass a variable in the parameter position ? i.e.,
me.Controls.Remove(strVariable)
I assume from your naming convention that strVariable stores the name
of the control. If you instead store a reference to the control
itself, you could just pass it in as it is.
Mattias
--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/|http://www.dotnetinterop.com
Please reply only to the newsgroup.
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