How I can replace a certain text with a table

3 posts, 0 answers
  1. Harald
    Harald avatar
    48 posts
    Member since:
    Oct 2013

    Posted 12 Apr 2015 Link to this post

    I would replace the text %Doctors% at the runtime by a table. The following code does not work.

    private void ReplaceAllMatches(string Parameter, Telerik.Windows.Documents.Model.Table NewTable)
    {
    this.myViewer.Document.Selection.Clear(); // this clears the selection before processing
    DocumentTextSearch search = new DocumentTextSearch(this.myViewer.Document);
    List<Telerik.Windows.Documents.TextSearch.TextRange> rangesTrackingDocumentChanges = new List<Telerik.Windows.Documents.TextSearch.TextRange>();
    foreach (var textRange in search.FindAll(Parameter))
    {
    Telerik.Windows.Documents.TextSearch.TextRange newRange = new Telerik.Windows.Documents.TextSearch.TextRange(new DocumentPosition(textRange.StartPosition, true), new DocumentPosition(textRange.EndPosition, true));
    rangesTrackingDocumentChanges.Add(newRange);
    }
    foreach (var textRange in rangesTrackingDocumentChanges)
    {
    this.myViewer.Document.Selection.AddSelectionStart(textRange.StartPosition);
    this.myViewer.Document.Selection.AddSelectionEnd(textRange.EndPosition);
    this.myViewer.InsertTable(NewTable,true);
    textRange.StartPosition.Dispose();
    textRange.EndPosition.Dispose();
    }
    }

     

  2. Tanya
    Admin
    Tanya avatar
    405 posts

    Posted 15 Apr 2015 Link to this post

    Hi Harald,

    I believe the observed behavior might be related to the fact that the Table elements are passed by reference and you are trying to insert the same table in more than one position. Could you verify this is the case? If yes, I suggest passing different Table objects to the InsertTable() method.

    Hope this helps.

    Regards,
    Tanya
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Harald
    Harald avatar
    48 posts
    Member since:
    Oct 2013

    Posted 15 Apr 2015 in reply to Tanya Link to this post

    Yes, I would like to insert the same table in different positions. After I modified the code, it works.

    ...

    foreach (var textRange in rangesTrackingDocumentChanges)
    {
    this.myViewer.Document.Selection.AddSelectionStart(textRange.StartPosition);
    this.myViewer.Document.Selection.AddSelectionEnd(textRange.EndPosition);
    this.myViewer.Delete(true);
    this.myViewer.InsertTable(NewTable,true);
    textRange.StartPosition.Dispose();
    textRange.EndPosition.Dispose();
    }

    ...

Back to Top