# Incorrect Words and Suggestions

> Find misspelled words with Check and IncorrectWords, create suggestions with CreateSuggestions, and replace MisspelledWords in a Windows Forms TextControl.

- **Product:** TX Spell .NET for Windows Forms
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Spell .NET for Windows Forms > Spell Checking > Incorrect Words and Suggestions
- **3292 words**
- **Web URL:** https://docs.textcontrol.com/tx-spell-dotnet-winforms/spell-checking/suggestions/
- **LLMs URL:** https://docs.textcontrol.com/tx-spell-dotnet-winforms/spell-checking/suggestions/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-spell-dotnet-winforms/spell-checking/suggestions/llms-full.txt

---

Behind every red underline and every entry of the spell check context menu are two lists: the words the spell checker found incorrect, and the suggestions it created for one of them. Your code can read both, to build a correction interface of its own, to report the mistakes in a text, or to replace a word with its best suggestion. What follows covers where the lists come from, what each entry holds, and how TX Text Control keeps its own list of misspelled words.

### How the Two Lists Are Filled

A [TXSpellChecker](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/txspellchecker/llms-full.txt) fills its lists on request, and each request replaces what the previous one found:

| You call | It fills | With |
|---|---|---|
| [Check](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/txspellchecker/check-method/llms-full.txt) | [IncorrectWords](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/txspellchecker/incorrectwords-property/llms-full.txt) | An [IncorrectWordCollection](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/incorrectwordcollection/llms-full.txt): every incorrect word of the text you passed |
| [CreateSuggestions](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/txspellchecker/createsuggestions-method/llms-full.txt) | [Suggestions](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/txspellchecker/suggestions-property/llms-full.txt) | A [SuggestionCollection](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/suggestioncollection/llms-full.txt): the suggestions for one word, closest match first |

Both use the dictionaries in [Dictionaries](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/txspellchecker/dictionaries-property/llms-full.txt). `Check` must not be called while the spell check dialog is open; it throws an exception.

A `TextControl` of TX Text Control that is connected to the spell checker does not use these two lists for its underlines. It keeps its own collection of misspelled words, described [below](#work-with-the-misspelled-words-of-tx-text-control).

### Find the Incorrect Words of a Text

This button handler checks the text of a `TextBox` and lists each incorrect word with its position in a `ListBox`. The form has a `TXSpellChecker` called `txSpellChecker1` from the toolbox:

```csharp
private void buttonCheck_Click(object sender, EventArgs e)
{
    txSpellChecker1.Check(textBox1.Text);

    listBoxWords.Items.Clear();

    foreach (TXTextControl.Proofing.IncorrectWord incorrectWord in txSpellChecker1.IncorrectWords)
    {
        listBoxWords.Items.Add($"{incorrectWord.Text} at {incorrectWord.Start}, {incorrectWord.Length} characters");
    }

    labelCount.Text = $"{txSpellChecker1.IncorrectWords.Count} incorrect word(s)";
}
```

The code works as follows:

- `Check(textBox1.Text)` checks the text against the dictionaries. An overload, `Check(string, CultureInfo)`, also uses the dictionaries of the default dictionary folder that match the language you pass.
- Each entry is an [IncorrectWord](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/incorrectword/llms-full.txt). Its [Text](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/spelledword/text-property/llms-full.txt), [Start](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/spelledword/start-property/llms-full.txt) and [Length](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/spelledword/length-property/llms-full.txt) say which word it is and where. `Start` counts from 0, so `textBox1.Select(incorrectWord.Start, incorrectWord.Length)` selects the word.
- `IncorrectWords.Count` is the number of incorrect words; 0 means the text is correct.

An `IncorrectWord` has two more properties:

- **[IsDuplicate](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/incorrectword/isduplicate-property/llms-full.txt)** is `true` when the word is spelled correctly but repeats the word in front of it, as in "the the".
- **[Language](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/incorrectword/language-property/llms-full.txt)** is the language the word was checked in, or `null` when no specific language was set.

The *Check simple text* sample of the setup uses the count to tell the user whether a text box holds mistakes:

![A form with a text box containing "spellling", a Check spelling button and a message box that says "The text box contains misspelled words."](https://docs.textcontrol.com/assets/img/tx-spell-dotnet-winforms/textbox-check-message.9ae6e420.webp)

### Create Suggestions for a Word

`CreateSuggestions` takes one word and fills `Suggestions`. With a maximum, it stops after that many suggestions; without one, it creates all it can find:

```csharp
private void listBoxWords_SelectedIndexChanged(object sender, EventArgs e)
{
    if (listBoxWords.SelectedIndex < 0) return;

    TXTextControl.Proofing.IncorrectWord incorrectWord = txSpellChecker1.IncorrectWords[listBoxWords.SelectedIndex];

    // The five closest matches for the selected word
    txSpellChecker1.CreateSuggestions(incorrectWord.Text, 5);

    listBoxSuggestions.Items.Clear();

    foreach (TXTextControl.Proofing.Suggestion suggestion in txSpellChecker1.Suggestions)
    {
        listBoxSuggestions.Items.Add(suggestion.Text);
    }
}
```

The code works as follows:

- The indexer of `IncorrectWords` counts from 0, like the list box, so the selected line and the word match.
- `CreateSuggestions(incorrectWord.Text, 5)` creates the five best suggestions. The collection is sorted by closeness, so `Suggestions[0]` is the best one.
- Each [Suggestion](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/suggestion/llms-full.txt) has one property, [Text](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/suggestion/text-property/llms-full.txt).

`CreateSuggestions` has four overloads:

| Overload | Suggestions from |
|---|---|
| `CreateSuggestions(string incorrectWord)` | The selected dictionaries, all suggestions |
| `CreateSuggestions(string incorrectWord, int max)` | The selected dictionaries, at most `max` suggestions |
| `CreateSuggestions(string incorrectWord, CultureInfo language)` | The selected dictionaries and those of the default dictionary folder in `language` |
| `CreateSuggestions(string incorrectWord, int max, CultureInfo language)` | The same, at most `max` suggestions |

The suggestions take the keyboard into account, so a key next to the intended one counts as a likely typo. Since version 10.0, they also use the replacement rules, the `REP` flag, of a Hunspell dictionary, which map common misspellings, such as a missing accent or "f" for "ph", to the correct spelling; [Version 10.0](https://docs.textcontrol.com/tx-spell-dotnet-winforms/whats-new/1000/#suggestions-from-the-rep-flag) describes the change.

### Choose Which Dictionaries Check and Suggest

Every [Dictionary](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/dictionary/llms-full.txt) in `Dictionaries` has two switches, both `true` by default:

- **[IsSpellCheckingEnabled](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/dictionary/isspellcheckingenabled-property/llms-full.txt)** decides whether `Check` uses the dictionary.
- **[IsGetSuggestionsEnabled](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/dictionary/isgetsuggestionsenabled-property/llms-full.txt)** decides whether `CreateSuggestions` uses it.

A dictionary of technical terms can therefore accept words during the check without filling the suggestions with them. [Loading and Managing Dictionaries](https://docs.textcontrol.com/tx-spell-dotnet-winforms/dictionaries/managing/llms-full.txt) covers adding dictionaries.

### Work With the Misspelled Words of TX Text Control

A `TextControl` with a connected spell checker keeps the words it underlines in [MisspelledWords](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/misspelledwords-property/llms-full.txt), a [MisspelledWordCollection](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/misspelledwordcollection/llms-full.txt) of the text part that has the input focus: the main text, a header or footer, or a text frame. Its entries are [MisspelledWord](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/misspelledword/llms-full.txt) objects, which differ from an `IncorrectWord` in a few ways:

|  | `IncorrectWord` | `MisspelledWord` |
|---|---|---|
| Belongs to | TX Spell .NET, after `Check` | TX Text Control, kept up to date as the user types |
| First character | `Start` counts from 0 | `Start` counts from 1 |
| Collection index | From 0 | From 1 |
| Can be marked as ignored | No, it has no such property | Yes, [IsIgnored](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/misspelledword/isignored-property/llms-full.txt) keeps it without the underline |

To correct a word in the editor, get it from the collection, create suggestions for its text, and pass the replacement to [Remove](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/misspelledwordcollection/remove-method/llms-full.txt). This handler replaces the misspelled word at the input position with its best suggestion:

```csharp
private void buttonCorrect_Click(object sender, EventArgs e)
{
    // The misspelled word at the input position, or the next one
    TXTextControl.MisspelledWord misspelledWord = textControl1.MisspelledWords.GetItem();
    if (misspelledWord == null) return;

    txSpellChecker1.CreateSuggestions(misspelledWord.Text, 1);

    if (txSpellChecker1.Suggestions.Count > 0)
    {
        // Replace the text of the word with the suggestion
        textControl1.MisspelledWords.Remove(misspelledWord, txSpellChecker1.Suggestions[0].Text);
    }
}
```

The code works as follows:

- [GetItem](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/misspelledwordcollection/getitem-method/llms-full.txt) without arguments returns the misspelled word at the input position. If there is none, it returns the next one, and after the last word it starts again at the first. Another overload takes a mouse location in pixels, for a word under the pointer.
- `Remove(misspelledWord, text)` replaces the word's text with the suggestion. `Remove(misspelledWord)` without a text only drops the word from the collection and leaves the text as it is.

The spell check context menu offers the same kind of correction for the word the user right-clicked:

![A context menu over the misspelled word "sampke" with the suggestions sample, spake, smoke, samples and sampler.](https://docs.textcontrol.com/assets/img/tx-spell-dotnet-winforms/textcontrol-context-menu.5b60b5a7.webp)

The blog article [Interactive Spelling Suggestions Using TX Spell .NET](https://www.textcontrol.com/blog/2014/07/30/interactive-spelling-suggestions-using-tx-spell-net/) shows the suggestions in a panel of labels and replaces the misspelled word at the input position with `MisspelledWords.Remove` when the user clicks one.

The same calls correct words automatically while the user types. The blog article [AutoCorrect Using TX Text Control and TX Spell .NET](https://www.textcontrol.com/blog/2017/08/17/autocorrect-using-tx-text-control-and-tx-spell-net/) handles the `KeyPress` event of the `TextControl`: when the user types a delimiter such as a space or a period right after a misspelled word, it creates one suggestion and replaces the word with it through `MisspelledWords.Remove`. A word the user changes back is left alone the second time.

### Check Text Without a User Interface

The [TXSpell](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/txspell/llms-full.txt) class has the same `Check`, `IncorrectWords`, `CreateSuggestions` and `Suggestions` members, without the dialogs, the context menus and the events. It suits code that only checks text, such as a validation in a background task, and it must be initialized with [Create](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/txspell/create-method/llms-full.txt) first. [Checking Text in Code](https://docs.textcontrol.com/tx-spell-dotnet-winforms/getting-started/in-code/llms-full.txt) introduces `TXSpell` step by step.

### Next Steps

- [As-You-Type Checking](https://docs.textcontrol.com/tx-spell-dotnet-winforms/spell-checking/as-you-type/llms-full.txt): let TX Text Control underline misspelled words while the user types.
- [Ignore Settings](https://docs.textcontrol.com/tx-spell-dotnet-winforms/spell-checking/ignore-settings/llms-full.txt): decide which words `Check` skips, and how duplicated words are reported.
- [Spelling Correction Modes and UI Provider](https://docs.textcontrol.com/tx-spell-dotnet-winforms/spell-checking/correction-modes/llms-full.txt): bind a correction form of your own to the current word and its suggestions.
- [Suggestion Controls](https://docs.textcontrol.com/tx-spell-dotnet-winforms/user-interface/suggestions/llms-full.txt): set up the suggestion lists of the dialog and the context menu, or show suggestions in a `ListBox`.

---

## Nearby

- **Previous:** [Checking on Demand](https://docs.textcontrol.com/tx-spell-dotnet-winforms/spell-checking/on-demand/llms-full.txt)
- **Next:** [Ignore Settings](https://docs.textcontrol.com/tx-spell-dotnet-winforms/spell-checking/ignore-settings/llms-full.txt)
