Solved

Usercontrol and loosing data

Posted on 2002-04-12
13
232 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 69

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
 
LVL 69

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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 100 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now