User Control Property Lifetime [???]

Merchand

Well-known member
Joined
Dec 28, 2005
Messages
73
Location
USA Eastcoast
Programming Experience
10+
I'm looking for the right terminology but can find it right now, sorry...

Anyway, I vb6 we had the property bag to store the initial values of properties and to keep them after the user changed them.

What is the proper way to do this in dot net? Save them to a xml configuration file or use a dynamic property? :confused:

Any guidance is greatful!
 
The word I was looking for is "Preserve" the state of the properties or dynamically preserve the values.

Anyway, I had created this UserControl called StatusBar has several constituent controls like two statusbars and several public properties. I wanted to expose these public properties as dynamic. However, in the user control I can't seem to expose them. I can expose them as dynamic properties in the test application called TestStatusBar.

I really would like to save/preserve these values in the user control and prevent the using program from having to create his/her own way to preserve them.

Please tell me the correct way to preserve property values in a user control. Thanks!
 
jmcilhinney,

Thanks for the feedback and link! You are right I was looking for the word Persist!

I was trying to do a non-primative type as dynamic property on Friday and it would not convert my type to a string, blah, blah...

Anyway, My real question is how do I really persist my property values for my usercontrol inside my usercontrol? In VB6 we had the property bag.

I have my statusbar usercontrol almost finished but inorder to presist the values I had to make them dynamic in my testing application. I don't want to require my user (other programmers) to make the properties dynamic themself... aka more work for them.

I understand that I can write code to store the property values in an xml configuration file but is there not a built-in way for this to work? Maybe I'm just not understanding the app configuration idea fully. Maybe I'll read all of this on-line reference (MSDN Lib) stuff and see if the light bulb goes off.

I have read most of it before. I'm looking for a good book on how to create usercontrols and custom controls via inheritance if you know of any good vb.net books. I can read C# and understand it but would rather have a good book on windows custom controls in vb.net. I think there may be a market for a good vb.net custom controls book... I can't believe there are not a few good ones yet. Thanks Again!! :)
 
Config files were originally supposed to be read-only. You can read values using the Configuration namespace but you cannot write values. You can use an XmlDocument object to write to the config file, which is in XML format, but no changes you make will be reflected through the Configuration namespace until you restart the app. VB 2005 has the My.Settings object to simplify things but I'm not 100% sure how much it adds as I haven't used it myself yet. The easiest thing for you may be to just include a nested Settings class in your UserControl. You can then assign all the values that you want to save to properties of an instance of that class and serialise it to save them, then deserialise to load. You could give the file a meaningful name like MyUserControl.config and save and load from Application.StartupPath.
 
jmcilhinney,

Thanks for the good feedback and ideas!!!

I have basically moved this post to the Component Development forum under the post titled "Persist Data in User Control". I believe you and I and JohnH are all on the same page as using serialization/deserialization as the way to perserve data for a user control. JohnH has left a good link if your interested in it.

Please provide feedback to my last reply to the "Persist Data in User Control" post. Thanks!
 
Back
Top