Copy e Paste TableCell

5 posts, 0 answers
  1. Marcello
    Marcello avatar
    58 posts
    Member since:
    Apr 2013

    Posted 05 Dec 2014 Link to this post

    Hi,

    In a separate thread (so I can't access RadRichTextBox object) I manipulate a RadDocument.
    Now, I want to copy the TableCell "source" into the TableCell "destination"

    For the style and options I use:
    destination.CopyPropertiesFrom(source);

    For the content I use:
    foreach (Block b in source.Blocks)
    destination.Blocks.Add((Block)b.CreateDeepCopy());

    All work good but, then CreateDeepCopy method generates a document that is not possible to export as pdf.
    Workarounds?

    Thank,
    marc.
  2. Marcello
    Marcello avatar
    58 posts
    Member since:
    Apr 2013

    Posted 09 Dec 2014 in reply to Marcello Link to this post

    I try to rephrase the question.

    What is the best strategy for copy & paste a cell style and cell content from a tablecell to another.
    If it is possible, using only RadDocument and without using RadRichTextBox object.

    Thanks,
    marc.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Tanya
    Admin
    Tanya avatar
    403 posts

    Posted 09 Dec 2014 Link to this post

    Hi Marc,

    You can use DocumentFragment and get the content of the source cell as a selection. Also, when direct access to RichTextBox is not possible, you can use the very similar API of RadDocumentEditor. Please, look at the example below for more clarity.

    var cell = sourceDocument
                .EnumerateChildrenOfType<TableCell>()
                .First();
     
    DocumentPosition start = new DocumentPosition(sourceDocument);
    start.MoveToStartOfDocumentElement(cell);
    DocumentPosition end = new DocumentPosition(sourceDocument);
    end.MoveToEndOfDocumentElement(cell);
    sourceDocument.Selection.SetSelectionStart(start);
    sourceDocument.Selection.AddSelectionEnd(end);
     
    var fragment = new DocumentFragment(sourceDocument.Selection);
     
    RadDocumentEditor editor = new RadDocumentEditor(this.targetDocument);
     
    editor.Document.CaretPosition.MoveToStartOfDocumentElement(this.targetDocument              .EnumerateChildrenOfType<TableCell>()            .FirstOrDefault());
    editor.InsertFragment(fragment);
     
    this.targetDocument.EnumerateChildrenOfType<TableCell>().FirstOrDefault().CopyPropertiesFrom(cell);

    The CopyPropertiesFrom() method in the above snippet is intended to copy the properties of the section itself - background color, width, etc. If you only want to copy the content you can omit it.
     
    Hope this helps.

    Regards,
    Tanya
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  5. Marcello
    Marcello avatar
    58 posts
    Member since:
    Apr 2013

    Posted 10 Dec 2014 in reply to Tanya Link to this post

    Hi Tanya,

    Tanks very much.With the RadDocumentEditor object I can work really good.
    In my case the target document is the same of source document, I used with success:

    //Seleziono e copio il frammento
    d.Selection.Clear();
    start.MoveToStartOfDocumentElement(sourcecell);
    end.MoveToEndOfDocumentElement(sourcecell);
    d.Selection.SetSelectionStart(start);
    d.Selection.AddSelectionEnd(end);
    f = new DocumentFragment(d.Selection);
    d.Selection.Clear();
     
    //Seleziono e incollo il frammento
    e.Document.CaretPosition.MoveToStartOfDocumentElement(destinationcell);
    e.InsertFragment(f);

    Now, the only part of code that's work in principal thread are:

    IDocumentFormatProvider pd = new XamlFormatProvider();
    using (FileStream stream = File.Open(mDoc.Path, FileMode.Open))
        d = pd.Import(stream);

    and

    mEditor.Document = d;

    I work with big files (more than 200 pages), is possible get a "progress report" for this two actions?

    Thanks,
    marc.
  6. Tanya
    Admin
    Tanya avatar
    403 posts

    Posted 13 Dec 2014 Link to this post

    Hi Marcello,

    The progress bar should use the UI thread to render, but unfortunately the two actions you are performing are on the UI thread as well. This means that the thread is already busy and that is why is not possible to show something similar.

    Let me know if you have any other questions.

    Regards,
    Tanya
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
UI for WPF is Visual Studio 2017 Ready