By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,256 Members | 1,272 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,256 IT Pros & Developers. It's quick & easy.

delete controls

P: n/a
after adding controls to a panel on my form, i need to delete them. does
anybody know how to programatically delete controls?

'my add function works
For i = 0 To DirectCast(dgRoutingTable.DataSource, DataView).Count()
Dim u As New RoutingControl.RoutingControl
With u
..Comments = i.ToString
..Location = New System.Drawing.Point(0, 136 * (i - 1))
End With
Me.Panel1.Controls.Add(u)
Next i
'my delete function doesnt work
For i = 0 To DirectCast(dgRoutingTable.DataSource, DataView).Count()
Dim u As RoutingControl.RoutingControl
Me.Panel1.Controls.Remove(u)
Next i
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Your code
Dim u As RoutingControl.RoutingControl
Me.Panel1.Controls.Remove(u) Is trying to place an uninstantiated control object to the Remove Method.

See below for an example which works.

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim u As New Button
With u
.Text = "Boo"
.Name = "ThatButton"
.Location = New System.Drawing.Point(0, 0)
End With
Me.Panel1.Controls.Add(u)
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click

For Each c As Control In Panel1.Controls

If c.Name = "ThatButton" Then
Panel1.Controls.Remove(c)
End If

Next

End Sub

--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--
"s.lustre" <s.******@maneyaircraft.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl... after adding controls to a panel on my form, i need to delete them. does
anybody know how to programatically delete controls?

'my add function works
For i = 0 To DirectCast(dgRoutingTable.DataSource, DataView).Count()
Dim u As New RoutingControl.RoutingControl
With u
.Comments = i.ToString
.Location = New System.Drawing.Point(0, 136 * (i - 1))
End With
Me.Panel1.Controls.Add(u)
Next i
'my delete function doesnt work
For i = 0 To DirectCast(dgRoutingTable.DataSource, DataView).Count()
Dim u As RoutingControl.RoutingControl
Me.Panel1.Controls.Remove(u)
Next i

Nov 21 '05 #2

P: n/a
S lustre,

Typed in this message so try it yourself and watch typos

\\\
for i as integer = me.controls.count-1 to 0 step -1
if typeof me.controls(i) IS RoutingControl.RoutingControl then
me.controls.remove(me.controls(i))
end if
next
///
I hope this helps

Cor
Nov 21 '05 #3

P: n/a
thanks Cor and OHM
finally got it to work

For i = Me.Panel1.Controls.Count - 1 To 0 Step -1
If TypeOf Me.Panel1.Controls(i) Is RoutingControl.RoutingControl Then
Me.Panel1.Controls.Remove(Me.Panel1.Controls(i))
End If
Next
Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.