/// <summary> /// Method to insert number on cell focus /// </summary> /// <param name="sender">The object that initiated the event.</param> /// <param name="e">The event arguments for the event.</param> private void InsertNumber(object sender, RoutedEventArgs e) { if (CheckBoxEnableNumber.IsChecked == true) { TextBox currentCell = sender as TextBox; string selectedNumber = this.FindSelectedNumber(); if (!currentCell.Name.Contains("Note")) { currentCell.Text = selectedNumber; } else { string cellname = currentCell.Name; string x = cellname.Substring(8, 1); string y = cellname.Substring(9, 1); string gamecellName = "Cell" + x + y; TextBox gameCell = FindName(gamecellName) as TextBox; if (string.IsNullOrWhiteSpace(gameCell.Text)) { List <string> tags = new List <string>(); string currentTags = currentCell.Text; foreach (char c in currentTags) { tags.Add(c.ToString()); } if (!tags.Contains(selectedNumber)) { tags.Add(selectedNumber); } List <string> sortedTags = tags.OrderBy(c => c).ToList(); currentCell.Text = string.Empty; foreach (var tag in sortedTags) { currentCell.Text += tag; } NoteGrid.Focus(); } } } }