private void NoteTitleTB_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { if (!string.IsNullOrEmpty(NoteTitleTB.Text) && !string.IsNullOrWhiteSpace(NoteTitleTB.Text)) { if (NoteTitleTB.Text != Current_Note.Name) { if (!Duplicate_Note(NoteTitleTB.Text)) { NotesLV.Sorting = SortOrder.None; Note_Changes.Remove(Current_Note.Name); Note_Changes.Add(NoteTitleTB.Text, NoteBodyTB.Text); Current_Note.Name = NoteTitleTB.Text; Current_Note.Text = NoteTitleTB.Text; NotesLV.Sorting = SortOrder.Ascending; NotesLV.Sort(); } else { MessageBox.Show("Duplicate note titles are not allowed.", "Duplicate Note Title", MessageBoxButtons.OK, MessageBoxIcon.Error); NoteTitleTB.Text = Current_Note.Name; NoteTitleTB.Focus(); NoteTitleTB.SelectAll(); } } } e.SuppressKeyPress = true; } }
private void AddNoteBT_Click(object sender, EventArgs e) { ListViewItem temp = new ListViewItem() { Name = "blanknote", Text = "blanknote" }; if (Duplicate_Note("blanknote")) { MessageBox.Show("A blank note already exists, please edit this note before adding another.", "Duplicate Blank Note", MessageBoxButtons.OK, MessageBoxIcon.Error); NotesLV.SelectedItems.Clear(); NotesLV.Items[Get_Blank_Note_Index()].Selected = true; NotesLV.Select(); NoteTitleTB.Focus(); DeleteNoteBT.Visible = true; } else { NotesLV.Sorting = SortOrder.None; NotesLV.Items.Insert(0, temp); NotesLV.SelectedItems.Clear(); NotesLV.Items[0].Selected = true; NotesLV.Select(); NoteTitleTB.Focus(); if (NotesLV.Items.Count == 1) { Current_Note = NotesLV.SelectedItems[0]; Current_Note.Font = BoldFont; NoteTitleTB.Enabled = true; NoteBodyTB.Enabled = true; NoteTitleTB.Text = Current_Note.Name; NoteBodyTB.Text = string.Empty; NotesLV.Select(); DeleteNoteBT.Visible = true; } } }