broadbent
asked on
Removing a control
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?
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
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
ASKER
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
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
ASKER
RemoveKey was not the answer by the way.
Remove(index) was just as good
Remove(index) was just as good
Me.Controls.RemoveByKey("B
or
Dim ControlToRemove as string = "Button1"
Me.Controls.RemoveByKey(Co