This question is locked. New answers and comments are not allowed.
I have a fairly straightforward problem. I have some sample text in a RichTextBox that I'm searching for very simple tags in; i.e. <DTG/>.
My document's content is just text (no tables or anything fancy):
The "Find/Replace" dialog works flawlessly to find each instance of <DTG/>. Note that I am not using any special Regex, just the literal value. I use the dialog to search the document many times and it always finds 5 instances of <DTG/>.
(Edit)
If I highlight (via the ribbon bar) the 3rd and 4th instance of <DTG/>, the Find/Replace dialog returns erroneous results for my search.
(End Edit)
Now I want to do the exact same thing using DocumentTextSearch. It does work, the first time only. Subsequent calls give me partial, and then finally only 1 result. I am invoking the search on a button click with the same content as above in the document.
I do have a function that clears all highlighting before running the SearchAndHighlight code. I used the same code as presented in this forum to clear out highlighting.
If I comment out the highlight line, then the FindAll() works consistently each time I click my button and run this method.
I really need a deterministic way to "Unhighlight", "Search", and finally "Highlight" from clicking a button.
My document's content is just text (no tables or anything fancy):
Serial: (X)<DTG/>Content: This is<DTG/> some con<DTG/>tent, that I am <DTG/>testing out richtext find programmatically<DTG/>.The "Find/Replace" dialog works flawlessly to find each instance of <DTG/>. Note that I am not using any special Regex, just the literal value. I use the dialog to search the document many times and it always finds 5 instances of <DTG/>.
(Edit)
If I highlight (via the ribbon bar) the 3rd and 4th instance of <DTG/>, the Find/Replace dialog returns erroneous results for my search.
(End Edit)
Now I want to do the exact same thing using DocumentTextSearch. It does work, the first time only. Subsequent calls give me partial, and then finally only 1 result. I am invoking the search on a button click with the same content as above in the document.
private void SearchAndHighlight( RadDocument doc, String search, RadRichTextBox rtb, Color highlight){ doc.Selection.Clear(); DocumentTextSearch search = new DocumentTextSearch( doc ); foreach( var textRange in search.FindAll( search ) ) { doc.Selection.AddSelectionStart( textRange.StartPosition ); doc.Selection.AddSelectionEnd( textRange.EndPosition ); } // set highlight rtb.ChangeTextHighlightColor( highlight ); doc.Selection.Clear();}I do have a function that clears all highlighting before running the SearchAndHighlight code. I used the same code as presented in this forum to clear out highlighting.
If I comment out the highlight line, then the FindAll() works consistently each time I click my button and run this method.
// set highlight - this messes up subsequent calls to search.FindAll()!!!// rtb.ChangeTextHighlightColor( highlight );I really need a deterministic way to "Unhighlight", "Search", and finally "Highlight" from clicking a button.