1

Hi everyone i have a little problem. I get the items from this array

this.HeaderFields = new string[]{ "PROJ_ID", "MODEL", "ESN", "LOCATION", "DATATYPE", "TESTTYPE", "TEST", "TRRDG", "RDG", "TESTDATE", "TESTTIME" };

and set them into a CheckedListBox with this line of code

checkedlstBoxHeaderField.Items.AddRange(settings.HeaderFields);
Controls.Add(checkedlstBoxHeaderField);

That works. When i open my winforms i want to check some of the values and than with OK Button to go nextStep and then when i reopen the form i want to see all items checked and unchecked. I try so

settings.HeaderFields = checkedlstBoxHeaderField.CheckedItems.OfType<string>().ToArray();

but with these line of code i became just the checked items. Please help....

2 Answers 2

2
settings.HeaderFields = checkedlstBoxHeaderField.Items.OfType<string>().ToArray();
Sign up to request clarification or add additional context in comments.

1 Comment

Then save this string array somewhere before closing this page
0

Simply hide and show the form to persist your selections, OR

//save your data to file

//Whole List
settings.HeaderFields = checkedlstBoxHeaderField.Items.OfType<string>().ToArray();
System.IO.File.WriteAllLines(@"C:\TestFolder\AllData.txt", HeaderFields );

//Selected List
settings.HeaderFields = checkedlstBoxHeaderField.CheckedItems.OfType<string>().ToArray();
System.IO.File.WriteAllLines(@"C:\TestFolder\SelectedData.txt", HeaderFields );



//Read Them back from files

settings.HeaderFields  = System.IO.File.ReadAllLines(@"C:\TestFolder\AllData.txt");
checkedlstBoxHeaderField.Items.AddRange(settings.HeaderFields);
Controls.Add(checkedlstBoxHeaderField);

settings.HeaderFields  = System.IO.File.ReadAllLines(@"C:\TestFolder\SelectedData.txt");
//now loop through the Checkbox list add select the accoring to the data from SelectedData.txt


System.IO.File.Delete(@"C:\TestFolder\SelectedData.txt");
System.IO.File.Delete(@"C:\TestFolder\AllData.txt");

Or you can save them to datatables

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.