/// <summary> /// Occurs when the content of a cell is clicked, used for the actions behind the icons /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void grid_CellContentClick(object sender, DataGridViewCellEventArgs e) { // if the row is valid if (e.RowIndex < 0 || e.RowIndex >= grid.RowCount && grid.Rows[e.RowIndex] == null) { return; } // and there is a word entry bound var we = grid.Rows[e.RowIndex].DataBoundItem as WordEntry; if (we == null) { return; } if (grid.Columns[e.ColumnIndex].Name == "Ignore") { // toggle ignore of the word entry and redraw the row we.Ignore = !we.Ignore; grid.InvalidateRow(e.RowIndex); UpdateStatistics(); } else if (grid.Columns[e.ColumnIndex].Name == "AddToDictionary") { // add the word to the custom dictionary we.IsUnknownWord = false; we.UnknownType = ""; we.Suggestion = we.Text; manager.AddToDictionary(we.Text); //redraw the row grid.InvalidateRow(e.RowIndex); UpdateStatistics(); } else if (grid.Columns[e.ColumnIndex].Name == "Copy") { // copy either the suggestion or the text if the suggestion is empty to the fixed text column for the current row if (string.IsNullOrEmpty(we.Suggestion)) { we.FixedText = we.Text; } else { we.FixedText = we.Suggestion; } we.Ignore = false; // redraw the row grid.InvalidateRow(e.RowIndex); UpdateStatistics(); } }
private void AddToDictionaryAndIgnoreEntry(int[] rowIndexes) { // Reset cell editing before we start replacing cell contents grid.EndEdit(); foreach (var rowIndex in rowIndexes) { // find bound word entry or return if none available var we = grid.Rows[rowIndex].DataBoundItem as WordEntry; if (we == null) { continue; } // add the word to the custom dictionary (if already present or something matching a rule we do nothing) if (!we.IsUnknownWord) { continue; } var isNewWord = manager.AddToDictionary(we.Text); if (!isNewWord) { continue; } we.IsUnknownWord = false; we.IsUserAdded = true; // Make sure the entry can be colored green and colors gray if ignored later on we.FixedText = ""; we.Ignore = false; //redraw the row grid.InvalidateRow(rowIndex); } UpdateStatistics(); }