Error : FromElement must not be null

2 posts, 0 answers
  1. Sopan
    Sopan avatar
    34 posts
    Member since:
    May 2012

    Posted 02 Sep 2013 Link to this post

    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 
  2. Petya
    Admin
    Petya avatar
    975 posts

    Posted 04 Sep 2013 Link to this post

    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 >>
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top