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

Copy e Paste TableCell

4 Answers 152 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Marcello
Top achievements
Rank 1
Iron
Marcello asked on 05 Dec 2014, 10:54 AM
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.

4 Answers, 1 is accepted

Sort by
0
Marcello
Top achievements
Rank 1
Iron
answered on 09 Dec 2014, 08:19 AM
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.
0
Tanya
Telerik team
answered on 09 Dec 2014, 04:36 PM
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.

 
0
Marcello
Top achievements
Rank 1
Iron
answered on 10 Dec 2014, 09:06 AM
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.
0
Tanya
Telerik team
answered on 13 Dec 2014, 08:24 AM
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.

 
Tags
RichTextBox
Asked by
Marcello
Top achievements
Rank 1
Iron
Answers by
Marcello
Top achievements
Rank 1
Iron
Tanya
Telerik team
Share this question
or