RadRichTextBox Selection by index

4 posts, 1 answers
  1. Oren
    Oren avatar
    21 posts
    Member since:
    Mar 2012

    Posted 04 Mar 2014 Link to this post

    Hello,
    I'm migrating a project that uses some "Textboxs" to "RadRichTextbox" and i need some help.

    In my old code i have a function that implements a "find & Replace" feature by selecting the found word.
    it does so by using the select(startIndex,Length) of the Textbox.

    I need  a way to implement a similar way to do so with the RadRichTextbox, As in, given a start index and length, it should select the text.
    my RadRichTextbox is bound using a "TxtDataProvider"

    Any help will be greatly appreciated.
    Oren

    P.S
    i know there is a built in "find and replace" in the RadRichTextBox but i still need it to work my way, i can't use the built in way.
  2. Yancho
    Admin
    Yancho avatar
    72 posts

    Posted 07 Mar 2014 Link to this post

    Hi Oren,

    Thank you for choosing RadRichTextBox!

    The control is a quite complex one and the document model supports many features. For this reason the internal logic does not actually depend on length or numeric indices, but uses DocumentPositions. Document elements are not associated with length, nor are document positions with a particular letter in the word since there is other content that might be present on a position - annotation, image, formatting symbol.

    Please take a look at this help articles about Search and Selection functionalities for a reference.

    Basically, if you are going to replace a word, you perform a search for a string and then you could do as you please with the results. The code-snippet below illustrates how to create a find/replace method:
    private void buttonFind_Click(object sender, RoutedEventArgs e)
    {
        this.radRichTextBox.Document.Selection.Clear();
        DocumentTextSearch search = new DocumentTextSearch(this.radRichTextBox.Document);
        foreach (var textRange in search.FindAll(this.textBox.Text))
        {
            this.radRichTextBox.Document.Selection.AddSelectionStart(textRange.StartPosition); this.radRichTextBox.Document.Selection.AddSelectionEnd(textRange.EndPosition);
            this.radRichTextBox.Insert(sometext);
        }
    }

    I hope this helps! Let me know how it goes.

    Regards,
    Yancho
    Telerik

    DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

  3. DevCraft banner
  4. Oren
    Oren avatar
    21 posts
    Member since:
    Mar 2012

    Posted 11 Mar 2014 in reply to Yancho Link to this post

    Hi Yancho,
    Thank you very much, it works.

    I do have another some unrelated question maybe you can help me with,

    Spell checking in a radRichTextBox doesn't work in RTL languages, in some post in the telerik forums i found, that its a known bug, that should get fixed in a future release, is there a time frame for this?

    thank you again
    Oren.
  5. Answer
    Yancho
    Admin
    Yancho avatar
    72 posts

    Posted 13 Mar 2014 Link to this post

    Hi Oren,

    I’m glad to hear that everything works for you.

    As to your question, I’m very happy to inform you that Telerik RadRichTextBox already supports spellchecking for RTL languages. Please take a look at this article for reference how to use RadRichTextBox Spellcheck. A list of dictionaries could be found at this forum post. The desired dictionary could be added through the RadDictionary class which supports the loading of a dictionary directly from TDF files.

    Also, you could check this forum post about how to use RadRichTextBox spell checking functionality for Arabic text in WPF framework. In Silverlight, it’s pretty much the same.

    I hope this helps! Let me know if you have other comments or questions. I would be glad to provide any assistance.

    Regards,
    Yancho
    Telerik
     

    DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

     
Back to Top