Solved

Removing a control

Posted on 2006-11-30
5
264 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
ID: 18045582
Use RemoveByKey like:

Me.Controls.RemoveByKey("Button1")

or

dim ControlToRemove as string
0
 
LVL 10

Expert Comment

by:Kinger247
ID: 18045589
Use RemoveByKey like:

Me.Controls.RemoveByKey("Button1")

or

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

Expert Comment

by:Fernando Soto
ID: 18045680
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
ID: 18045810
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
ID: 18045823
RemoveKey was not the answer by the way.
Remove(index) was just as good
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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 need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

830 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