Solved

Removing a control

Posted on 2006-11-30
5
282 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

695 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