This is a migrated thread and some comments may be shown as answers.

How to know if the Selection is Multiline or Singleline

1 Answer 51 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Kushagra
Top achievements
Rank 1
Kushagra asked on 17 Feb 2014, 11:11 AM
How do we know programmatically that the selection done by the user is a single line selection and doesnt contain any combination. We want to know how will we identify if the user has selected table/images or plain text.

Kushagra

1 Answer, 1 is accepted

Sort by
0
Missing User
answered on 19 Feb 2014, 06:05 PM
Hi Kushagra,

Thank you for contacting us!

If you are going to identify the elements in the user's selection, I would suggest you to create a new document from the selection. Then you should enumerate its table/image elements and determine whether they exist. 

The following code-snippet demonstrates how this could be accomplished:
if (!this.radRichTextBox.Document.Selection.IsEmpty)
{
    RadDocumentEditor documentEditor = new RadDocumentEditor(new RadDocument());
    documentEditor.InsertFragment(new DocumentFragment(this.radRichTextBox.Document.Selection));
 
    if (documentEditor.Document.EnumerateChildrenOfType<Table>().Count() > 0)
    {
        MessageBox.Show("Contains table");
    }
    if (documentEditor.Document.EnumerateChildrenOfType<ImageInline>().Count() > 0)
    {
        MessageBox.Show("Contains image");
    }
}

I hope this helps!
Let me know if you have other comments or questions.

Regards,
Yancho
Telerik
Tags
RichTextBox
Asked by
Kushagra
Top achievements
Rank 1
Answers by
Missing User
Share this question
or