Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,

I am creating a form and I have a few TextBoxes. I want to save the data to a text file (I have already done that). When I click on the "Save" button, it will save the data to a file and then change the button text to "Edit" (I have done this).

Now, after clicking on the save button, I want the TextBoxes to be disabled and when I click on the edit button, it will re-enable. If the data in the TextBoxes is changed then it will ask for confirmation for saving, else it will show no changes made and overwrite the existing file.

Please help.

What I have tried:

I have taken two save buttons, two edit buttons and for the value change I have taken two TextBoxes and comparing them. But I feel that this is not right. I don't want two of each controls.
Posted
Updated 27-Apr-18 19:16pm
Comments
BillWoodruff 28-Apr-18 11:02am    
The user chooses 'Edit : the TextBoxes are enabled; the user modifies the contents of the TextBoxes and chooses Save ... now the user cancels the Save : if that happens don't you need to restore the modified TextBoxes Text ?

1 solution

Taken this is Windows Forms, you can use Control.Enabled Property (System.Windows.Forms)[^] to enable or disable the control.


What comes to the edited data. Add a new boolean variable to your program, for example
C#
bool changesSaved;

Once you save the changes, set it to true. Also wire Control.TextChanged Event (System.Windows.Forms)[^] and in that event set the changesSaved to false. Now when needed you can investigate ig the changes have been changed or not. Just remember to set the initial value correctly for example if you read the data from a file.
 
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