Clear all selections

I did not find a easy way clearing all selections after I called

var regex = new System.Text.RegularExpressions.Regex(termsPattern);
var textSearchResults = richTextBoxAdv.FindAll(regex, FindOptions.CaseSensitive);
for (int j = 0; j < textSearchResults.Count; j++)
 {
    TextSearchResult result = textSearchResults[j];
     richTextBoxAdv.Selection.Select(result.Start,result.End);
     richTextBoxAdv.Selection.CharacterFormat.HighlightColor = highlightColor;
 }

The only options that worked was

richTextBoxAdv.Selection.Select(richTextBoxAdv.Document.DocumentStart,richTextBoxAdv.Document.DocumentEnd);
richTextBoxAdv.Selection.CharacterFormat.HighlightColor = HighlightColor.NoColor; 

But this is very slow (take about 2 seconds) even with a short text.
Any ideas?


3 Replies 1 reply marked as answer

KG Kalaivannan Ganesan Syncfusion Team February 23, 2026 06:09 AM UTC

Hi Frank,

When the entire document is selected from DocumentStart to DocumentEnd and the highlight color is set to NoColor, the SfRichTextBoxAdv iterates through all paragraphs and tables in the document. It then processes each inline element under them and sets the HighlightColor property to None.

Since the complete document content is iterated and highlight colors are updated, the time taken for this operation is expected.


If your requirement is to:

  • Highlight specific text in the document,
  • Perform your operations, and
  • Then reset the highlight color back to NoColor,

we recommend using the WordDocument (DocIO) component. DocIO is optimized for Word document processing and performs these operations much faster. After processing the document using DocIO, you can load the updated content back into SfRichTextBoxAdv.


Recommended Workflow

  1. Load the document into a WordDocument instance (DocIO).
  2. Search for the required text and retrieve the matching results.
  3. Apply highlight color (e.g., Red) for the required matches.
  4. Load the modified document in SfRichTextBoxAdv.
  5. After completing your operations, use the same WordDocument instance to reset the highlight color to NoColor.
  6. Load the cleared document back into SfRichTextBoxAdv.

This method provides faster performance because DocIO is specifically designed for efficient Word document processing.

Please refer below UG for more information:
Find and replace in Word document | DocIO | Syncfusion

Where, SfRichTextBoxAdv is a UI editing control, and it updates both the document and the visual interface. Because of this, bulk operations take a bit more time, which is expected for interactive UI components.

We have attached the sample application and the demonstration video for your reference. Please review them for more details.


Attachment: SfRichTextBoxAdv_DocIO_Highlight_ff6efe15.zip


FF Frank Fischbach February 23, 2026 06:38 AM UTC

Hi Kalaivannan,

many thanks for the swift and helpful reply. Just one more question: In the attached sample project, you load the document from a word file. I have, however, the text in a SfRichTextBoxAdv (and data is save in a SQL database). 

How do I load the  SfRichTextBoxAdv  document into a WordDocument instance (DocIO)?

Best Regards

Frank



KG Kalaivannan Ganesan Syncfusion Team February 24, 2026 06:18 AM UTC

Frank, we can load SfRichTextBoxAdv content into a DocIO WordDocument by following a supported workflow:

  1. Save the SfRichTextBoxAdv document into a stream using its built‑in export feature (supports DOCX, DOC, RTF, HTML, etc.).
    Import and Export in WPF RichTextBox control | Syncfusion
  2. Load that stream into a DocIO WordDocument instance, since DocIO supports opening Word documents directly from streams.
    Loading & Saving Word document in C# | DocIO | Syncfusion
  3. After loading into DocIO, you can safely perform operations such as search, replace, highlighting, formatting, and other document manipulations available in DocIO.
  4. Once the modifications are complete, you can load the updated WordDocument back into SfRichTextBoxAdv, which supports loading content from a DocIO WordDocument object through its import APIs.

We have attached a sample application and a video illustration that walk through this workflow end‑to‑end. Please review them for further details.


Attachment: SfRichTextBoxAdv__Load_Into__DocIO_9f70809c.zip

Marked as answer
Loader.
Up arrow icon