Can code-behind be updated automatically when controls are being deleted in a form?

ullenulle
ullenulle used Ask the Experts™
on
Hi there.

Another question in my self-study of vb.NET:

I just tried deleting a control on a form, and I double-clicked a control because I wanted to add some vb-code. Later I deleted the control, but then I see, that the vb-code remains even though the control is gone.... and of course that causes a compiling error.
Is there a setting to automatically delete the related vb-code to a control, if the control is deleted?

Best regards

Ulrich
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Pretty sure you can't do this automatically but you really wouldn't want to do that anyway. Chances are that automatic deletion would more often cause errors than resolve them.

You have to figure that if code was automatically deleted, you WILL end up deleting something that was referenced by a different bit of code. There are some 3rd party tools that can search for unreferenced code and remove it but best practice is to really just remove code manually. Some things (usually destructive operation) are better done with human intelligence.

Author

Commented:
I do prefer to keep things under control on my own. Just need to make sure to clean up right after deleting a control. :-)
AndyAinscowFreelance programmer / Consultant

Commented:
I've never heard of an 'auto delete' possibility.  

I agree with gr8gonzo it could cause problems with deleting code that was required, depends on how the coder works.
Peter HutchisonSenior Network Systems Specialist

Commented:
I this situation, the creation display and management of controls would be entirely done in user code and not via the designer. Objects references could be stored in arrays or collections and thus checked and referenced by indexed items within arrays or collections during the running of the code. So it is possible.

Author

Commented:
Thank you all for your responses.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial