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

Error : FromElement must not be null

1 Answer 97 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Sopan
Top achievements
Rank 1
Sopan asked on 02 Sep 2013, 08:58 AM
Hi,

I am trying to remove table from blocks so above error message comes and table not able to remove.

my code
Telerik.Windows.Documents.Model.Span spanbox = editor.Document.CaretPosition.GetCurrentSpanBox().AssociatedSpan;
                StyleDefinition expansionstyle = new StyleDefinition();
                    expansionstyle.SpanProperties = new SpanProperties() { FontWeight = FontWeights.SemiBold, ForeColor = Colors.Brown };
                    if (spanbox.FontWeight == FontWeights.SemiBold && spanbox.ForeColor == Colors.Brown)
                    {
                        Telerik.Windows.Documents.Model.Section currsect = editor.Document.CaretPosition.GetCurrentSectionBox().AssociatedSection;
                        bool check = editor.Document.CaretPosition.MoveToNextInline();
                        var documentelement = editor.Document.CaretPosition.GetCurrentTableBox();
 
                        if (documentelement!=null && documentelement.GetType() == typeof(TableLayoutBox))
                        {
                            spanbox.Tag = Guid.NewGuid().ToString();
                            //var tableStyle = editor.Document.StyleRepository["TableGrid"] as StyleDefinition;
                            Telerik.Windows.Documents.Model.Table tbl = documentelement.AssociatedTable;
 
                            if (tbl != null)
                            {
 
                                TableHelper Thelp = new TableHelper();
                                Thelp.TableReferenceId = spanbox.Tag;
                                foreach (Telerik.Windows.Documents.Model.TableRow c in tbl.Rows)
                                {
                                    TableRowHelper rowhelper = new TableRowHelper();
 
                                    foreach (Telerik.Windows.Documents.Model.TableCell cell in c.Cells)
                                    {
                                        TableCellHelper cellhepl = new TableCellHelper();
                                        foreach (DocumentElement block in cell.Blocks)
                                        {
 
                                            DocumentElementCollection docelement = new DocumentElementCollection(block);
                                            foreach (var item in block.Children)
                                            {
                                                docelement.Add(item);                                              
 
                                            }
 
                                            cellhepl.DocumentElementCollection.Add(docelement);
                                        }
 
                                        rowhelper.TableCellCollection.Add(cellhepl);
                                    }
 
                                    Thelp.TableRowHelperCollection.Add(rowhelper);
                                }
                                TableHelpCollection.Add(Thelp);
                                ExpandedColl.Add(spanbox.Tag, tbl);
                                //stylecoll.Add(spanbox.Tag, tableStyle);
 
                            }
                            styles.Add(spanbox.Tag, documentelement.AssociatedTable.Style);
                            currsect.Blocks.Remove(tbl);
 
                            //editor.Document.StyleRepository.Add(tableStyle);
                             
                            
                        }


how to resolve this error 

1 Answer, 1 is accepted

Sort by
0
Petya
Telerik team
answered on 04 Sep 2013, 03:44 PM
Hi Sopan,

As mentioned by my colleague Anna in this forum thread, manipulating directly the document elements in a measured document is highly inadvisable. Instead, you should use the methods of RadRichTextBox or RadDocumentEditor.

The DeleteTable() method of RadRichTextBox deletes the table where the caret is currently located if there is such. You could also call the DeleteTable(Table table) method in case the caret is not located in the table element which you want to remove.

I hope this helps!

Regards,
Petya
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
RichTextBox
Asked by
Sopan
Top achievements
Rank 1
Answers by
Petya
Telerik team
Share this question
or