I have written my code in Visual C++ using .NET Framework. I have several checkboxes on my GUI and I would like to give the user the option of saving the current state of the checkboxes. I took care of the save file, now the loading of the file is where I have my problem. The checkbox names are saved in the file, when the user loads this file back into the GUI, I read the checkbox names line by line and I am suppose to check whatever checkbox name it is.
Example:
checkbox_file.txt content:
checkBox1
checkBox5
When checkbox_file.txt is loaded back into the application,
"checkBox1" is saved as a String^
I am trying to save this string to a checkbox so that I may do this:
checkBox->checked = true;
thanks in advance.
Expand|Select|Wrap|Line Numbers
- private: System::Void read_file(String ^strFileName)
- {
- /* save the contents of the file line by line as elements in the lines array */
- array<String^> ^lines = System::IO::File::ReadAllLines(strFileName);
- System::Windows::Forms::CheckBox^ check = (gcnew System::Windows::Forms::CheckBox());
- for(int i = 0; i < lines->Length; i++)
- {
- /* as long as the string is not an empty line */
- if(lines[i]->CompareTo("") != 0)
- {
- check->Name = lines[i];
- check->Checked = true;
- }
- }
- }