GetSelectedText is empty

3 posts, 0 answers
  1. Sean
    Sean avatar
    2 posts
    Member since:
    Sep 2013

    Posted 17 Sep 2013 Link to this post

    I would like to get the selected text from the rich text box.

    When I drag a selection in the ui and then query the selected text I get an empty string:
    var thisIsEmpty = rtb.Document.Selection.GetSelectedText()

    If I use the Document.CaretPosition to set the selection to the beginning and end of the word, the GetSelectedText() returns that selected word. However, that is just the word under the caret - not necessarily all of the selected words.
    text = MainMessageBodyTextBox.Document.Selection.GetSelectedText();

    My questions:
    • why is the initial selection empty when dragged from the ui (my document is ReadOnly, but changing that didn't seem to make a difference)
    • how can I retrieve all of the selected words from the Selection (the words will be contiguous)

    thank you

  2. Petya
    Petya avatar
    973 posts

    Posted 20 Sep 2013 Link to this post

    Hello Sean,

    I was unable to replicate inconsistent behavior of the GetSelectedText() method. Could you please share with us what version of RadControls for Silverlight you are using?

    Generally, once you've retrieved the selection you can split the string in order to obtain all separate words in it.

    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. DevCraft banner
  4. Sean
    Sean avatar
    2 posts
    Member since:
    Sep 2013

    Posted 22 Sep 2013 Link to this post

    Hello Petya,

    we are using version 2013.2.611.1050.

    However, I have just found the problem. There was an event handler firing (mouse down) in our code that had moved the document CaretPosition. On the mouse up, the document was still reporting a selection, but the caret move appears to have set the selected text to an empty string.

    This was my misunderstanding of the document selection vs the selection with caret interaction. Sorry for the work caused.

    thank you, Sean
Back to Top