?
Solved

Trying to savesettings on form close but not able to get values from controls.

Posted on 2004-10-12
11
Medium Priority
?
218 Views
Last Modified: 2010-04-23
OK I have a form myForm with a user control on it called myControl. I have a variety of control values on myControl which I load from the registry in the constuctor using getSetting.

WHen myForm is closed, it takes myControl with it. At this point I want to saveSettings for each of the controls on myControl so that the changes the user made are not lost.

I have a sub saveAllSettings which I have tried placing in the finalize and in the dispose methods, but when it comes to saveSetting reading textBox1.text, the textbox.text value is empty, when there was definately some text htere before.

Is there no good time to run save settings? Do I need to make a save button/wire it up to events, or can I do it automatically on form close as I wish? I dont want to make a public method and have myForm call it.
0
Comment
Question by:mcintyre321
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 19

Expert Comment

by:arif_eqbal
ID: 12285228
See Dispose needs to be called explicitly and Finalize is not reliable, you don't know when it would be called.

I think it is better if you call your SaveAllSettings Function in Form_Closing event
0
 
LVL 9

Expert Comment

by:checoo
ID: 12285231
why dont you write the code in form closing event..??
0
 

Author Comment

by:mcintyre321
ID: 12285251
its not a form - its a UserControl which doesn't have form_closing I dont think...
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Expert Comment

by:checoo
ID: 12285312
but your question starts with

OK I have a form myForm with a user control on it called myControl. I have a variety of control values on myControl which I load from the registry in the constuctor using getSetting....

so i guess you have placed the usercontrol on a form..if so the form myForm will have a closing event
0
 

Author Comment

by:mcintyre321
ID: 12285358
yesss.... but I don't want to have to write a bit of code in every form i use the control in telling it to kick off a dispose method in one of its . It should all be held within the usercontrol, which I can just place on the form.

I don't know why all the filled out textboxes reset to "" by the time dispose and finalize get run. I would have thought they would be intact up til one of them...
0
 
LVL 19

Expert Comment

by:arif_eqbal
ID: 12285392
Well then i don't think there's much option left

You will have to have a public method in the UserControl and call it on Form Closing

UserControl has Dispose function also and you can write the SaveAllSetting call there too but remeber to call Mybase.Dispose and also you'll need to call dispose explicitly from the Form on Form Closing

0
 

Author Comment

by:mcintyre321
ID: 12285565
that sucks. So much for abstraction. The dispose is useless as it seems to have removed the values from the sub controls by then.

I'll leave this Q open for a bit and then give you the points if no-one comes up with anything. I didn't want the form to have anything to do with it, but if thats how it is, thats how it is. ta
0
 

Author Comment

by:mcintyre321
ID: 12285569
sorry i sound really bitter!
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 12287254
Have you tried using the HandleDestroyed Event?

According to the remarks you should be able to query your control from within it:

     "During the HandleDestroyed event, the control is still a valid Windows control and the Handle can be recreated by calling the RecreateHandle method."

~IM
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

862 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