Click here to Skip to main content
15,899,026 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a checkbox and beside of it is a textbox, now i want to save the value of textbox if the checkbox is check and if not dont save by a button. Can you show some codes please....
Posted
Updated 16-Nov-14 15:26pm
v2
Comments
Sergey Alexandrovich Kryukov 16-Nov-14 21:25pm    
And what's the problem?
What have you tried so far?
—SA
BillWoodruff 17-Nov-14 0:17am    
What do you mean by "save the value:" save the Text ? save how ?save where ?
[no name] 17-Nov-14 0:18am    
hi dude your question is not clear dude .post your code what have you so for tried

step 1:

create save method

C#
private void SaveData()
{
if(checkbox.Checked)
{
 //write save process codes 
} 

}


step 2:

call the save method in check box CheckedChanged event

C#
private void checkBox_CheckedChanged(object sender, EventArgs e)
    {
       SaveData();
    }
 
Share this answer
 
Comments
berrymaria 17-Nov-14 0:44am    
i agree to this...
First you need to decide on what event will it be saved. Either when check changed or button was clicked. Then where/how you want to save it- to a file, database or other.

assume it is a button click event and saved to a file and method called is SaveText():
you only need to test for when checkbox.Checked is true

C#
void SaveText()
{
   
string txt = textbox.Text;
if(checkbox.Checked){
// save to file
}
// else do nothing
}
 
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