Click here to Skip to main content
15,913,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi In my windows application i have two forms
Mainform , subform
In my subform i have checkbox
My problem is to save change in my checkbox when hide subform becouse i read value for checkbox in mainform

What I have tried:

I try to add this code to button in subform
This.visible=false;
But checkbox back to default when reopen subform
Posted
Updated 18-Apr-17 21:35pm
Comments
sameer549 19-Apr-17 3:35am    
you cannot achieve this directly, you need to save the checkbox state in some variable and then hide/show checkbox in subform load event.

http://stackoverflow.com/questions/14616958/saving-the-form-state-then-opening-it-back-up-in-the-same-state

1 solution

Changing the state of anything isn't permanent unless you specifically code for it to be.

The best way to handle this would be to add a setting:
1) Open your projects Properties in the solution explorer, and double click on "Settings.settings"
2) In the resulting grid, change the Name to "MySetting", and set the Value to "Defaulted value". Leave Type and Scope as "string" and "User" respectively.
3) Save and close the settings window.
4) To read your setting:
string s = Properties.Settings.Default.MySetting;
5) To write your setting:
Properties.Settings.Default.MySetting = "My new setting value";
Properties.Settings.Default.Save();
Then add code to the form save and load methods to use the saved setting and update the visible status of your checkbox in the form Load and Close events.
 
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