Improve company productivity with a Business Account.Sign Up

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 283
  • Last Modified:

Usercontrol and loosing data

I've made my own usercontrol but when i change the name
the control is "grayed out" and a number of properties is reset (for instance "Caption").

Any idea?
  • 5
  • 4
  • 2
  • +2
1 Solution
can you show us code?
Éric MoreauSenior .Net ConsultantCommented:
is your control project open in the same instance of VB as your test project? Be sure that all window (code and designer) related to your control are closed. Even with this precaution, there is a small bug that sometimes occurs and the controls remains grayed in the tool box. When this occurs, simply open the designer of your control and reclose it.
dgbAuthor Commented:
It is a lot of code and some other objects that make up the usercontrol

When we have a project in wich we want to use the usercontrol we simply add the usercontrol.

We don't have the controlwindow open and it is not that the control is grayed out in the toolbox but on the form
where we are using the control.
After the option Update Usercontrol (right mouseclick on form)
the grayed out part is solved but we've also lost some property values.
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Éric MoreauSenior .Net ConsultantCommented:
Have you used the wizard to build your control? There are some events that you need to handle into your control (like ReadProperties and WriteProperties).
Yes, it's: Right-click on the form and select "Update User Controls"

That will *recompile* the control, and restart it in run-mode.  Yes, you are in design mode, but control is 'running'.

Don't expect to see any properties you set previously:

Like you have a form running with an empty textbox, and you type "Hello" in textbox, now if you recompile and restart the project, you won't see that "Hello" (unless you save it to registry)

The same is with property pages - you are in design mode, but pages really are 'running'
or, from one PAQ:

Open Form1, right click on it, and select menu "Update UserControls"
This will update temporary CLSID for your control/class.

When you change code in your control, do not expect it will always use
existing data you entered into property page for your control on Form1.
Sometimes "Update UserControls" will do the job (compiling to pi code for VB
IDE, temporary registering, etc.), but if you are adding some properties or
changing arguments for your class methods, the best bet is to:
- first remove control from form1
- add your code in OCX project
- add control to form1 and set properties

You can compare your control with regular vb project.

Regular project (let’s say it’s a form with one textbox)

Textbox has some initial text property (.Text=” ”)
You press Run (this will compile your project to pi code), and in Run mode you CHANGE Text property
Now you stop Running your project, change some code, and press Run. Do you expect you’ll see data you
entered in previous Run? No, your data will be reset (.Text=” ”) and you’ll have to enter it again.

OCX project

Note that real job VB is doing when you work in design mode with 2 projects, is *very* complex (e.g.
your property page is *running* and is in design mode at the same time). When you change code in your
control, VB will have to recompile your control – it will do this secretly when you open form with your
control. After recompiling, it will restart your control – it will run InitProperties, etc.
Do not expect your data you entered before, will be always preserved.
dgbAuthor Commented:
emoreau :
Yes i have used the wizard.

ameba :
The thing is that there are no property pages open when i first place the usercontrol on the form and nothing happends but when i change the name the control is grayed out.

In some cases it works fine i can place controls and change names without any property values lost but in other cases i can not.
>The thing is that there are no property pages open

I mentioned property pages only to explain run/design duality.

>when i change the name the control is grayed out

If control is grayed, it means it must be 'recompiled'.  You probably changed the name of something inside user control.  If you change the name of usercontrol placed on the form, it shouldn't require 'recompile'.

>In some cases it works fine

If you don't change something that will change signature of some control method, it may work it out without complete recompile.

Many things are happening 'behind the scene' during design time in VB, and that is fantastic.

VB.NET still does not have that level of magic.
There is no "Edit and Continue" feature in it.
To change anything in the code, you must stop running and recompile...
dgbAuthor Commented:
Correct me if i am wrong but changing the name of a usercontrol on a form does not change anything wich would result in recompiling, so why thinks it needs to recompile.

I also checked the init of the usercontrol and only variables are changed not the objects within the usercontrol.
I agree, it shouldn't recompile.  Maybe it doesn't work the best possible way, or maybe the way they implemented it doesn't allow that.

I just tested it and if I only change name, it doesn't 'gray out'.
If I just open usercontrol designer, it grays out - without making any change.  Maybe they can do it better next time ...

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in Community Support that this question is:
- points to ameba
Please leave any comments here within the
next seven days.
dgbAuthor Commented:
Allthough i didn't get an anser to my question, other then
microsoft should do it better next time i will give the
points to ameba for the effort he made.

Thanks for the effort, let us hope microsoft will do it
better next time......
B?  That reminds me why I answer vb questions at different site now.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 4
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now