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

Highlight basing on indexes

1 Answer 56 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Naga
Top achievements
Rank 1
Naga asked on 22 Oct 2011, 02:36 AM
We have huge text being displayed inside a rich text box. We have implemented our custom Regular expression for advanced searches like Date > 1/1/200 which will look inside the text and will return say index of word for ex 1/12/2011, we represent it as word range which is essentially starting index and end index of the hit. Now I want to mix the above logic with highlighting infrastructure of the rich text box.


I m using the below code

ITextBasedDocumentFormatProvider

 

 

exporter = new TxtFormatProvider();

 

var documentTextMap = new DocumentTextMap(radRichTextBox.Document);

 

string text = exporter.Export((documentTextMap).Document);

 

WordHitEvaluator.WordRange[] wordRanges = wordHitEvaluator.Evaluate(text, fieldNames);

if (wordRanges != null)

 

foreach (WordHitEvaluator.WordRange wordRange in wordRanges)

{

 

TextRange textRange = documentTextMap.MapFromIndexInText(wordRange.Start,

wordRange.End - wordRange.Start);

radRichTextBox.Document.Selection.SetSelectionStart(textRange.StartPosition);

radRichTextBox.Document.Selection.AddSelectionEnd(textRange.EndPosition);

}

radRichTextBox.ChangeTextHighlightColor(

 

Colors.Red);

radRichTextBox.Document.Selection.Clear();


But for some reason it fails.Can you please let me know if this hybrid highlight is possible?

Thanks,
Naga.

1 Answer, 1 is accepted

Sort by
0
Boby
Telerik team
answered on 27 Oct 2011, 07:35 AM
Hello Naga,
SetSelectionStart will clear the current selection, you can use AddSelectionStart method instead.

Don't hesitate to contact us if you have other questions.


All the best,
Boby
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
RichTextBox
Asked by
Naga
Top achievements
Rank 1
Answers by
Boby
Telerik team
Share this question
or