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

RadDocument Insert in Selection range

1 Answer 146 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Manuel
Top achievements
Rank 1
Manuel asked on 28 Dec 2011, 05:45 PM
Hi there,

I've this code:

 private void ReplaceAllMatches(string toSearch, string toReplaceWith,RadDocument doc)
        {
          
            doc.Selection.Clear();
            
            DocumentTextSearch search = new DocumentTextSearch(doc);
            List<TextRange> rangesTrackingDocumentChanges = new List<TextRange>();
          
            foreach (var textRange in search.FindAll(toSearch))
            {
                TextRange newRange = new TextRange(new DocumentPosition(textRange.StartPosition, true), new DocumentPosition(textRange.EndPosition, true));
                rangesTrackingDocumentChanges.Add(newRange);
            }

            foreach (var textRange in rangesTrackingDocumentChanges)
            {
                doc.Selection.AddSelectionStart(textRange.StartPosition);
                
                doc.Selection.AddSelectionEnd(textRange.EndPosition);
                string textoSeleccionado = doc.Selection.GetSelectedText();

                DocumentPosition posInicial = textRange.StartPosition;
                DocumentPosition posFinal = textRange.EndPosition;
                
                DocumentPosition posTotal = new DocumentPosition(posInicial);
                //posTotal.MoveToCurrentLineStart();
                //posTotal.MoveToCurrentWordStart();

                
                doc.Insert(toReplaceWith,new Telerik.Windows.Documents.Model.Styles.StyleDefinition());
                textRange.StartPosition.Dispose();
                textRange.EndPosition.Dispose();
            }
        }

So I´ve the word that I want replace selected, how I can get that range to replace here, with RadDocument?

Thanks in advance,

1 Answer, 1 is accepted

Sort by
0
Boby
Telerik team
answered on 30 Dec 2011, 11:07 AM
Hello Manuel,
It looks you've found the answer in the other thread you opened. Don't hesitate to contact us if you have other questions.

Kind regards,
Boby
the Telerik team

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

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