473,379 Members | 1,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Deleting controls

WH
I put a few controls on a form at runtime like
Dim bt as Button
For n = to to 5
bt = new Button
...
Me.Controls.add(bt)
Next

How can I again delete them at runtime? I tried
For each bt in Me.controls
bt.dispose()
Next

But only a few controls disappear, some stay on the form.
bt = Nothing() does'nt do the job either
Is there a way to completely discard then from the form and from memory?
Thanks
WH
Dec 23 '06 #1
3 1010
You could add them to a collection as they are created and then refer to the
collection to remove them from the form later. I'm sure there are other ways
as well but this would work.

HTH

Martin

"WH" <wi**********@skynet.bewrote in message
news:45***********************@news.skynet.be...
>I put a few controls on a form at runtime like
Dim bt as Button
For n = to to 5
bt = new Button
...
Me.Controls.add(bt)
Next

How can I again delete them at runtime? I tried
For each bt in Me.controls
bt.dispose()
Next

But only a few controls disappear, some stay on the form.
bt = Nothing() does'nt do the job either
Is there a way to completely discard then from the form and from memory?
Thanks
WH


Dec 23 '06 #2
Hi WH,

You must remember to remove them from the form before disposing them.
So just before you dispose them, use me.controls.remove(bt).

Regards

Dec 27 '06 #3
Willy,

You add the buttons to the controls with Add, what command do you think
there is to Remove them from the Controls?

Keep in mind that if you remove buttons from a parent control that you do it
bottom up because the index is everytime regenerated.

It depends on were you created the buttons when they will be garbaged, but
normally you can forget to take actions in that because the Garbage
Collector does that.

Cor

"WH" <wi**********@skynet.beschreef in bericht
news:45***********************@news.skynet.be...
>I put a few controls on a form at runtime like
Dim bt as Button
For n = to to 5
bt = new Button
...
Me.Controls.add(bt)
Next

How can I again delete them at runtime? I tried
For each bt in Me.controls
bt.dispose()
Next

But only a few controls disappear, some stay on the form.
bt = Nothing() does'nt do the job either
Is there a way to completely discard then from the form and from memory?
Thanks
WH


Dec 27 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Lyn | last post by:
This one is driving me crazy. I have a table which stores pictures in an OLE Object column, one per record with a few other text fields (caption, date, etc). This table is maintained with a...
3
by: Eric Hudson | last post by:
A quick rant and a question. Why does the designer in VS2003 delete code about custom components that it can't load? I've had large sections of forms disappear in the blink of an eye just...
3
by: Wayne | last post by:
1. I have created my own class that inherits the textbox (called it CyanFocusTextBox). I put in some code and some new properties. All this works. I build the dll that contains this class...
3
by: meh | last post by:
Hi All; After creating a new tab if I delete the tab I cannot close my app from the X in the upper right of the window. NE1 have a clue why. Tried stepping through the delete seems to work fine...
1
by: Bjorn Sagbakken | last post by:
With ASP.NET 2.0: I have managed to create controls dynamically in an asp:table, populating them with database info, and even adding empty rows of controls for adding new data to the database....
1
by: John | last post by:
Hi Is it possible to enumerate all controls on a form and then save the info in an xml file via code? Is it possible to reverse the process i.e. read info from and xml and recreate all controls...
1
by: Alcestis | last post by:
Any help would be greatly appreciated. My problem is as follows: I have a program that dynamically creates any control (picture boxes, text boxes etc) on a panel, i want to be able to delete these...
2
by: Dylan Parry | last post by:
Hi, I'm writing a site, and I've have several HTML controls, such as UL elements, that are dynamically populated via the application I'm writing in C#. Sometimes there aren't any list items...
4
by: sphinney | last post by:
I'm not exactly sure how to start this post. My question is pretty simple, but it will take a little bit of context before I can state it. (And thanks in advance for taking the time to read this!) ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.