Solved

Removing a control

Posted on 2006-11-30
5
276 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

738 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