Solved

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

Posted on 2004-10-12
11
210 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +1
11 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

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

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!

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

688 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