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?
dgbAsked:
Who is Participating?
 
amebaConnect With a Mentor Commented:
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 ...
0
 
COAtheGREATCommented:
can you show us code?
0
 
É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.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
dgbAuthor Commented:
COAtheGREAT:
It is a lot of code and some other objects that make up the usercontrol

emoreau:
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.
0
 
É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).
0
 
amebaCommented:
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'
0
 
amebaCommented:
or, from one PAQ:

>>>>
Solution:
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
(.Text=”SomeNewText”)
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.
0
 
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.
0
 
amebaCommented:
>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...
0
 
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.
0
 
twalgraveCommented:
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

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.
0
 
dgbAuthor Commented:
twalgrave:
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.

ameba
Thanks for the effort, let us hope microsoft will do it
better next time......
0
 
amebaCommented:
B?  That reminds me why I answer vb questions at different site now.
0
All Courses

From novice to tech pro — start learning today.