# Checking Text Parts

> Steer the WPF spelling dialog through the text parts of a TextControl: count misspelled words per header, footer or frame and start in a header with SetNext.

- **Product:** TX Spell .NET for WPF
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Spell .NET for WPF > Spell Checking > Checking Text Parts
- **2128 words**
- **Web URL:** https://docs.textcontrol.com/tx-spell-dotnet-wpf/spell-checking/text-parts/
- **LLMs URL:** https://docs.textcontrol.com/tx-spell-dotnet-wpf/spell-checking/text-parts/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-spell-dotnet-wpf/spell-checking/text-parts/llms-full.txt

---

A document in TX Text Control is more than its main text. Headers, footers and text frames hold text of their own, and each of them is a separate *text part* with its own misspelled words. By default, spell checking covers all of them. When a letterhead in the header or a form in text frames should be left alone, or only the footers should be checked, the spell check dialog of TX Spell .NET can be steered from one text part to another.

### What Text Parts Are

The [TextParts](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/textparts-property/llms-full.txt) property of a `TextControl` returns a [TextPartCollection](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/textpartcollection/llms-full.txt) with every text part of the document. The first entry is the main text, a [MainText](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/maintext/llms-full.txt) object. Text frames ([TextFrame](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/textframe/llms-full.txt)) follow, and headers and footers ([HeaderFooter](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/headerfooter/llms-full.txt)) come last. Footnote sections are text parts, too.

All text parts implement [IFormattedText](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/iformattedtext/llms-full.txt), and each has its own list of misspelled words in [IFormattedText.MisspelledWords](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/iformattedtext/misspelledwords-property/llms-full.txt). The `MisspelledWords` property of the `TextControl` itself holds only the words of the text part that has the input focus.

### How the Dialogs Walk Through the Text Parts

Both spelling dialogs check every text part:

- The dialog of TX Text Control, opened with [TextControl.SpellCheckDialog](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/spellcheckdialog-method/llms-full.txt), starts with the main text and continues with the headers, footers and text frames.
- The [SpellCheckDialog](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/spellcheckdialog/llms-full.txt) of TX Spell .NET, opened with `Show(textControl1)`, also covers all text parts, and can be told which one to check next.

A choice in the dialog of TX Spell .NET can reach beyond the current text part. When the user clicks **Ignore All** or **Change All**, the word is ignored or changed in all text parts, because two properties are `true` by default:

| Property | Default | When `true` |
|---|---|---|
| [IgnoreInAllTextParts](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/spellcheckdialog/ignoreinalltextparts-property/llms-full.txt) | `true` | An ignore operation applies in all text parts |
| [ChangeInAllTextParts](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/spellcheckdialog/changeinalltextparts-property/llms-full.txt) | `true` | A change operation applies in all text parts |

Set them to `false` to keep each choice inside the text part where the user made it. Both work only when the dialog checks a `TextControl`.

### Count the Misspelled Words of Each Text Part

Before deciding what to check, you can find out where the mistakes are. This handler goes through the text parts and lists how many misspelled words each holds:

```csharp
private void buttonReport_Click(object sender, RoutedEventArgs e)
{
    listBoxReport.Items.Clear();

    foreach (TXTextControl.IFormattedText textPart in textControl1.TextParts)
    {
        string kind =
            textPart is TXTextControl.MainText ? "Main text" :
            textPart is TXTextControl.TextFrame ? "Text frame" :
            textPart is TXTextControl.HeaderFooter ? "Header or footer" :
            "Other";

        listBoxReport.Items.Add($"{kind}: {textPart.MisspelledWords.Count} misspelled word(s)");
    }
}
```

The code works as follows:

- `TextParts` enumerates the text parts as `IFormattedText` objects, main text first.
- The `is` tests tell the kinds apart; a footnote section counts as "Other" here.
- `MisspelledWords.Count` is the number of misspelled words the connected spell checker found in that part.

### Start the Dialog in a Chosen Text Part

The dialog of TX Spell .NET raises [SpellCheckDialogOpening](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/txspellchecker/spellcheckdialogopening-event/llms-full.txt) when `Show` opens it. Its argument has a [StateManager](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/spellcheckdialogopeningeventargs/statemanager-property/llms-full.txt), a [SpellCheckDialogStateManager](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/spellcheckdialogstatemanager/llms-full.txt), which gets and sets the word the dialog handles next. One overload of its [SetNext](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/spellcheckdialogstatemanager/setnext-method/llms-full.txt) method takes a misspelled word and the text part that contains it.

This handler makes the dialog begin with the first misspelled word of the first header or footer, rather than with the main text:

```csharp
private void txSpellChecker1_SpellCheckDialogOpening(object sender, TXTextControl.WPF.Proofing.SpellCheckDialogOpeningEventArgs e)
{
    foreach (TXTextControl.IFormattedText textPart in textControl1.TextParts)
    {
        if (!(textPart is TXTextControl.HeaderFooter)) continue;

        foreach (TXTextControl.MisspelledWord misspelledWord in textPart.MisspelledWords)
        {
            // Continue the check with this word of this header or footer
            e.StateManager.SetNext(misspelledWord, textPart);
            return;
        }
    }
}
```

The code works as follows:

- `SetNext(misspelledWord, iFormattedText)` sets the [MisspelledWord](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/misspelledword/llms-full.txt) the dialog shows next. The text part must belong to the `TextControl` the dialog checks; otherwise the method throws an exception.
- [NextMisspelledWord](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/spellcheckdialogstatemanager/nextmisspelledword-property/llms-full.txt) and [NextIFormattedText](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/spellcheckdialogstatemanager/nextiformattedtext-property/llms-full.txt) read what the dialog will show next, and in which text part.
- The event fires for the dialog of TX Spell .NET only, so open it with `txSpellChecker1.SpellCheckDialog.Show(textControl1)`. `txSpellChecker1` is the resource of the window, which the code-behind gets with `FindResource`, as [As-You-Type Checking](https://docs.textcontrol.com/tx-spell-dotnet-wpf/spell-checking/as-you-type/#use-the-spell-checker-in-code) shows. Attach the handler after that, with `txSpellChecker1.SpellCheckDialogOpening += txSpellChecker1_SpellCheckDialogOpening;`.

The same state manager is passed to the [DialogButtonClicked](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/txspellchecker/dialogbuttonclicked-event/llms-full.txt) and [SpellCheckDialogClosing](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/txspellchecker/spellcheckdialogclosing-event/llms-full.txt) events, so the dialog can be steered on while the user works through it. [Checking Multiple Controls](https://docs.textcontrol.com/tx-spell-dotnet-wpf/spell-checking/multiple-controls/llms-full.txt) uses the closing event to move on to the next editor.

### Check Only the Text Parts the User Chooses

The *TextControl\\SpellCheckDialog on specific text parts* sample of the setup combines these members. Its document has main text, a header, a footer and several text frames. Check boxes below the editor choose which kinds of text parts are checked, and **Spell Check Dialog** opens a dialog that shows only the misspelled words of the chosen parts:

![A TextControl with text frames and a header, the Spelling dialog on the misspelled word "sampke", and the check boxes MainText, TextFrames and HeaderFooters next to Apply To below the editor.](https://docs.textcontrol.com/assets/img/tx-spell-dotnet-wpf/textcontrol-text-parts.b4c3c6d1.webp)

The sample steers the dialog with the `SetNext` overload that names a text part. [Spell Checking Examples](https://docs.textcontrol.com/tx-spell-dotnet-wpf/examples/spell-checking/llms-full.txt) lists where the setup installs it, in C# and Visual Basic.

### Next Steps

- [Checking Multiple Controls](https://docs.textcontrol.com/tx-spell-dotnet-wpf/spell-checking/multiple-controls/llms-full.txt): continue the dialog with the next editor.
- [Checking on Demand](https://docs.textcontrol.com/tx-spell-dotnet-wpf/spell-checking/on-demand/llms-full.txt): open the two dialogs and choose between them.
- [Events](https://docs.textcontrol.com/tx-spell-dotnet-wpf/spell-checking/events/llms-full.txt): every event of the dialog, with its arguments.
- [Spell Check Dialog](https://docs.textcontrol.com/tx-spell-dotnet-wpf/user-interface/spell-check-dialog/llms-full.txt): the parts of the dialog the user works with.

---

## Nearby

- **Previous:** [Checking Multiple Controls](https://docs.textcontrol.com/tx-spell-dotnet-wpf/spell-checking/multiple-controls/llms-full.txt)
- **Next:** [Spelling Correction Modes and UI Provider](https://docs.textcontrol.com/tx-spell-dotnet-wpf/spell-checking/correction-modes/llms-full.txt)
