New to Telerik UI for WPF? Download free 30-day trial

Getting a List of All Tables in the Current Selection

Environment

Product Version
RadRichTextBox for WPF 2023.3.1010

Description

How to retrieve a list of all tables in the current selection in RadRichTextBox.

Solution

  1. Create a copy of the selection as a new RadDocument using the CreateDocumentFromSelection method of the document's selection.

  2. Iterate through the document and check for Table objects.

Here's an example implementation:

 public List<Table> GetTablesInSelection() 
 { 
      var documentFromSelection = this.richTextBox.Document.Selection.CreateDocumentFromSelection(); 
      return documentFromSelection.EnumerateChildrenOfType<Table>().ToList(); 
 } 
In this article