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

RadRichTextBox Selection by index

3 Answers 112 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Oren
Top achievements
Rank 1
Oren asked on 04 Mar 2014, 04:15 PM
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.

3 Answers, 1 is accepted

Sort by
0
Missing User
answered on 07 Mar 2014, 02:53 PM
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.

0
Oren
Top achievements
Rank 1
answered on 11 Mar 2014, 09:56 AM
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.
0
Accepted
Missing User
answered on 13 Mar 2014, 04:11 PM
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.

 
Tags
RichTextBox
Asked by
Oren
Top achievements
Rank 1
Answers by
Missing User
Oren
Top achievements
Rank 1
Share this question
or