private void loadStateToolStripMenuItem_Click(object sender, EventArgs e) { fileName = Foldername + "\\state2.xml"; DataToSave DataToResult = DataToSave.DeserializeACar(fileName); textBox1.Text = DataToResult.Textbox1; textBox2.Text = DataToResult.Textbox2; textBox3.Text = DataToResult.Textbox3; int[] itemindex = new int[checkedListBox1.Items.Count]; int itemIndex = 0; foreach (string item in checkedListBox1.Items) { for (int i = 0; i < DataToResult.AllCheckeditems.Count; i++) { if (item == DataToResult.AllCheckeditems[i]) { //MessageBox.Show(item.ToString()); itemindex[itemIndex] = 1; } } itemIndex++; } for (int i = 0; i < itemindex.Length; i++) { if (itemindex[i] == 1) { checkedListBox1.SetItemChecked(i, true); } } }
public static void SerializeADataToSave(string FilePath, DataToSave dataBlock) { using (Stream file = new FileStream(FilePath, FileMode.Create)) { myXmlSerializer.Serialize(file, dataBlock); } }
private void saveStateToolStripMenuItem_Click(object sender, EventArgs e) { if (checkedListBox1.CheckedItems.Count == 0) { MessageBox.Show("No checked items"); } else { fileName = Foldername + "\\state2.xml"; List <string> AllCheckediTems = new List <string>(); foreach (string itemChecked in checkedListBox1.CheckedItems) { MessageBox.Show(itemChecked.ToString()); AllCheckediTems.Add(itemChecked); } DataToSave DataBlock1 = new DataToSave(textBox1.Text, textBox2.Text, textBox3.Text, AllCheckediTems); DataToSave.SerializeADataToSave(fileName, DataBlock1); } }