Solved

Removing a control

Posted on 2006-11-30
5
236 Views
Last Modified: 2010-04-23
I have a form with an array of controls that I created.

Dim ik as Integer '  is the count of these controls

I want to remove the last control and I use this code to do so

    Controls.Remove(ListVItems(ik))       ' remove the control
      ListVItems(ik) = Nothing                 ' I'm not sure this is necessary
      ik -= 1                                          ' reduce the total
      ReDim Preserve ListVItems(ik)        '  reduce the array
      Refresh

but nothing happens.
What have I done wrong?
0
Comment
Question by:broadbent
  • 2
  • 2
5 Comments
 
LVL 10

Accepted Solution

by:
Kinger247 earned 125 total points
Comment Utility
Use RemoveByKey like:

Me.Controls.RemoveByKey("Button1")

or

dim ControlToRemove as string
0
 
LVL 10

Expert Comment

by:Kinger247
Comment Utility
Use RemoveByKey like:

Me.Controls.RemoveByKey("Button1")

or

Dim ControlToRemove as string = "Button1"
Me.Controls.RemoveByKey(ControlToRemove )
0
 
LVL 62

Expert Comment

by:Fernando Soto
Comment Utility
Hi broadbent;

Arrays are zero base in .Net so if ik is the total number of controls in the array then the last control in the array is ( ik - 1 ).

Fernando
0
 
LVL 4

Author Comment

by:broadbent
Comment Utility
You're quite right, I forgot to say that ik is set =-1

But the answer is quite simple. Just asking the question normally helps.
These controls are NOT on the form, but on a panel (so that I can use the AutoScroll)
MainPanel.Controls does work.

I'm an idiot, and I will happily give the points to Kinger247
0
 
LVL 4

Author Comment

by:broadbent
Comment Utility
RemoveKey was not the answer by the way.
Remove(index) was just as good
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now