Highlight basing on indexes

2 posts, 0 answers
  1. Naga
    Naga avatar
    6 posts
    Member since:
    Sep 2010

    Posted 21 Oct 2011 Link to this post

    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.
  2. Boby
    Admin
    Boby avatar
    685 posts

    Posted 27 Oct 2011 Link to this post

    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 >>

Back to Top