public void LoadNoteFile() { try { // Load the setting with the default path, if there is a setting. // Read a file and load the contents into the Note values combobox string startLocation; if (_dialogPath == false) { startLocation = System.IO.Path.GetDirectoryName(Project.Current.URI); } else { startLocation = AppSettings.Default.NoteFilePath; } OpenItemDialog openDialog = new OpenItemDialog() { Title = "Select a Note values file to load", MultiSelect = false, Filter = ItemFilters.textFiles, InitialLocation = startLocation }; string savePath; if (openDialog.ShowDialog() == true) { IEnumerable <Item> selectedItem = openDialog.Items; foreach (Item i in selectedItem) { System.IO.StreamReader file = new System.IO.StreamReader(i.Path); string line; while ((line = file.ReadLine()) != null) { EditNoteComboBox.AddItem(new ComboBoxItem(line)); } savePath = System.IO.Path.GetDirectoryName(i.Path); AppSettings.Default.NoteFilePath = savePath; } EditNoteComboBox.SelectedItem = EditNoteComboBox.ItemCollection.FirstOrDefault(); AppSettings.Default.Save(); _dialogPath = true; // is now set } } catch (Exception ex) { MessageBox.Show("Error in LoadNoteFile: " + ex.ToString(), "Error"); } }
public void SaveCustomNoteValues() { // Routine to load and maintain QA Note values within the combobox try { QueuedTask.Run(() => { // Get current custom Note value and save to new settings file // Update value of EditNoteComboBox var qaNoteValue = EditNoteComboBox.Text; if (qaNoteValue == null) { return; } // Don't add duplicates to the list string selectedNotevalue; bool duplicateFound = false; for (int i = 0; i < EditNoteComboBox.ItemCollection.Count; i++) { EditNoteComboBox.SelectedIndex = i; selectedNotevalue = EditNoteComboBox.SelectedItem.ToString(); if (selectedNotevalue == qaNoteValue) { duplicateFound = true; } } if (duplicateFound == false) { EditNoteComboBox.AddItem(new ComboBoxItem(qaNoteValue)); } EditNoteComboBox.Text = qaNoteValue; EditNoteComboBox.SelectedItem = qaNoteValue; }); } catch (Exception ex) { MessageBox.Show("Error in SaveCustomNoteValues: " + ex.ToString(), "Error"); } }