|
-
May 18th, 2005, 06:49 AM
#1
Thread Starter
Frenzied Member
Copy a form object into another
Hello everybody,
I need to maintain whether data on a screen has been changed or not. If data has been changed, then I need to give a pop-up warning on form close that your unsaved data will be lost, do you wish to continue.
For performing this, I created a generic function which takes two arguments of System.Windows.Forms.Form type. Then I iterate through all the controls and perform one-to-one checking with textbox text property, listbox selectedindex and so on. After performing this check, method return true or false.
The main thing is that when something on the form chages, I need to create a copy of the current state of the form in a form object. On close, call the function supplying two arguments, one is the state that was saved and other is the actual form that is this.
How do I save the state of the form, means when user types something or perform any changes, I need to copy the form into another object with the properties of data loaded in it.
Any ideas ??
Last edited by usamaalam; Jun 3rd, 2005 at 01:51 AM.
-
May 18th, 2005, 02:52 PM
#2
Addicted Member
Re: Copy a form object into another
Well just like you say you want to loop through each control and compare the values to verify if the user changed something, you can instantiate a new form object and copy all the values from the initial form in the newly instantiated form. And then, when you want to check to current user's form, compare each value to the original ones.
There are no stupid questions, but a whole bunch of dumb sayings !
Save time on database code, try DataLG !
-
May 18th, 2005, 03:39 PM
#3
Thread Starter
Frenzied Member
Re: Copy a form object into another
Yes. I have written the function which compare data in controls with one to one correspondence. But I cannot instantiate the temporary form object properly. When I send the temporary form object and actual form to the function, I get the same values in all the controls. What I think the form object is copied ByReference.
-
May 19th, 2005, 02:51 AM
#4
Lively Member
Re: Copy a form object into another
i think you can create an array list to store the data of the form when it is load, and then make comparation with the form control and array list, that should be done although it would be tedious.
if you instantiate a new form object and reference to the original form, then no matter what you change in original form will reflect to the newly instantiate form, because it is by reference, ie, they are pointing to same address.
p/s: i remember in vb, there is an event to keep track of the control changes, however, i am not sure for C#
-
May 19th, 2005, 04:42 PM
#5
Thread Starter
Frenzied Member
Re: Copy a form object into another
Maintaining two array lists or a flag variable are also solutions, but this functionality was not required in earlier versions of application and now I have developed more than 30 forms and client wants this functionality. Therefore, I am in seach of some generic solution, not to code differently on each form. I thought of the form technique because I wrote the comparison method in another class and thought to copy and paste the form instantiating code in all the forms.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|