How to know if the Selection is Multiline or Singleline

2 posts, 0 answers
  1. Kushagra
    Kushagra avatar
    16 posts
    Member since:
    May 2011

    Posted 17 Feb 2014 Link to this post

    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.

  2. Yancho
    Yancho avatar
    72 posts

    Posted 19 Feb 2014 Link to this post

    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.

Back to Top