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

DocumentTextSearch hanging at find function

1 Answer 69 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
mohd azidi
Top achievements
Rank 1
mohd azidi asked on 15 Feb 2016, 02:42 AM

hi, im using current Telerik WPF Q1 2015 and also try using current and i have a problem in my project with DocumentTextSearch. the function is to load  document xaml template and find text string and replace with table. but i have problem with DocumentTextSearch when searching text string from RadDocument its keep hanging when try to find text string. my code is like bellow : 

  public void ReplaceTable(ref RadDocument doc, string searchitem, Table RefTable)
        {
            doc.BeginUpdate();
            try
            {
                using (DocumentPosition startFindPosition = new DocumentPosition(doc.DocumentLayoutBox, true))
                {
                    var found = true;

                    while (found)
                    {
                        DocumentTextSearch textSearch = new DocumentTextSearch(doc);
                        TextRange find = textSearch.Find( Regex.Escape(searchitem), startFindPosition);

                        found = find != null;

                        if (found)
                        {
                            startFindPosition.MoveToPosition(find.EndPosition);
                            startFindPosition.AnchorToNextFormattingSymbol();

                            doc.CaretPosition.MoveToPosition(find.StartPosition);
                            find.SetSelection(doc);

                            //doc.Delete(false);
                            //doc.IncreaseLeftIndent();
                            //if (RefTable.Rows.Count == 1)
                            //{
                            //    doc.Insert("-");

                            //}
                            //else
                            //{
                            //    doc.InsertTable(RefTable);
                            //}
                            doc.Selection.Clear();


                            startFindPosition.RemoveAnchorFromNextFormattingSymbol();
                        }
                    }
                   
                }
            }
            catch (Exception e) { }
            finally
            {
                doc.EndUpdate();
                
            }
        }

i wait your reply

 

1 Answer, 1 is accepted

Sort by
0
Svetoslav
Telerik team
answered on 17 Feb 2016, 08:34 PM
Hi,

Thank you for contacting us.
 
I tested the attached code snippet but it seems that it is working as expected on my end. My guess is that the problem could be related to incorrectly structured document. For this reason, I would ask you to send us exact steps to reproduce, document file and the searched text. Once we are able to reproduce the issue, we will do our best to assist you. 

Regards,
Svetoslav
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
RichTextBox
Asked by
mohd azidi
Top achievements
Rank 1
Answers by
Svetoslav
Telerik team
Share this question
or