Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Usercontrol and loosing data

Posted on 2002-04-12
13
Medium Priority
?
278 Views
Last Modified: 2010-05-02
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?
0
Comment
Question by:dgb
  • 5
  • 4
  • 2
  • +2
13 Comments
 
LVL 1

Expert Comment

by:COAtheGREAT
ID: 6936189
can you show us code?
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 6936623
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
 

Author Comment

by:dgb
ID: 6936664
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 70

Expert Comment

by:Éric Moreau
ID: 6936676
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
 
LVL 15

Expert Comment

by:ameba
ID: 6936751
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
 
LVL 15

Expert Comment

by:ameba
ID: 6936782
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
 

Author Comment

by:dgb
ID: 6939945
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
 
LVL 15

Expert Comment

by:ameba
ID: 6940091
>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
 

Author Comment

by:dgb
ID: 6944356
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
 
LVL 15

Accepted Solution

by:
ameba earned 300 total points
ID: 6945042
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
 
LVL 16

Expert Comment

by:twalgrave
ID: 7754991
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
 

Author Comment

by:dgb
ID: 7785650
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
 
LVL 15

Expert Comment

by:ameba
ID: 7786021
B?  That reminds me why I answer vb questions at different site now.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question