Click here to Skip to main content
15,919,245 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,
Suppose that we have a form with different controls. let say a textbox and a chkbox. If a user types something and change check status, I would like that by closing the form and opening it again, I'll be able to see the status of the form just before closing(not the designed status). I need this to implement on a form with around 50 different controls. Would you please give me a hint for that?

what I need is somehow save the form. Since I need to get the user one of the following options: 1. Create New 2. Edit Existing. The Form actually gets the adjustments for running a simulation, so its difficult to adjust the preferences every time. Also different adjustments should be loadable in future.
Posted

Okay, so you need to store your values... there are two main ways of doing this.

1. Database
-----------------------
If you have a database, you simply create a table with fields to hold the control values at the time the form closes, then you simply load those values from the database when the form opens in 'edit mode' and set the controls appropriately.

2. File System
-----------------------
A little more basic would be saving the values to a file. You can either simply create a text file and write the control values on form close, or if you would like to get a bit wild, create a serializabe class to hold the forms control values... then your values can be written/read to/from a XML file.

If you need help with any method for storing values, you will probably want to ask a new question about a specific problem you are having with the code you have already done so folks can see what you've tried.

Good luck!
 
Share this answer
 
Comments
Amir_ait 12-Jul-11 21:00pm    
I dont have database.
On the second approach,there are some issues:
1. I have a complex user Control(which is basically a table of combobx and textbx in each row with variable number of rows) , which will be created several times depending on the end-user request.
2. some calculation will be triggered by importing new data
3. By clicking some buttons imported data will be verified and labeled as OK.
4. Properties of the controls are also of importance(not just their values).
What I mean there is highly likely to miss, critical event or property or value, by the second method.

Is there any option to safely save all the complications ?
fcronin 13-Jul-11 17:31pm    
The solution you want has to be designed, there is not built in ability to save all aspects of a dynamic form to handle all of your processing. What I have done in the past was create a serializable class that could handle everything about my form (controls, properties, values, selected values/items, etc etc). Then when your form closes, populate that class with all of the relevant information and Serialize() it (save to XML file). When you load a form for editing, you DeSerialize() (load from XML file) to re-create that class with all the relevant values as they were saved, then apply that information to your form appropriately.
You need to create a Finite-State Machine (FSM) for your form. There are no complication: you should describe everything in term of states. For example, if some calculations are triggered, where the result go? It should be reflected in some data members of the form. And so on. So, start with the analysis of each form in terms of state machine, don't think of preserving existing form functionality. Design form based on the model, not the other way around. When this is done, implement two operations: storing FSM and loading FSM, so the form would be populated with the data.

See http://en.wikipedia.org/wiki/Finite-state_machine[^].

FSM itself can be implemented based on enumeration type. Given a set of states, a FSM can be represented as a sub-set of the Cartesian square of this set, each element of the sub-set representing an allowed transition. I developed a generic class which implements the data indexed by the elements of Cartesian square build over the arbitrary enumeration type, so the formal mechanism is read. Please see my article Enumeration Types do not Enumerate! Working around .NET and Language Limitations[^], see the chapter "3.6 Cartesian Square".

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900