error while removing the DocumentElement from section ?

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

    Posted 04 Sep 2013 Link to this post


    I am trying to remove some Document Element as Paragraph, Table, Images from section under RadRichTextBox .
    But I want to implement the functionality which allow to add and remove the Document element on button click event.

    Suppose I want to remove table from Section so Table having collection of Rows, Row having collection of Cells, Cell having collection of DocumentElement.

    When I am get table from section and store it in local dictionary then table is come but not its inner collection like rows collection, cells collection (ie empty collection come), to solve this problem I have taken this values in my another collection.

    But after got all the inner collection value I am trying to remove the DocumentElement from section it throws an exception and If I try to remove this DocuemntElement without getting his inner collection values then it removes normally.

    reference code If I remove all comments then code thrown an error and with comment it run normally
    Telerik.Windows.Documents.Model.Paragraph NextPara;
               try {
                   Telerik.Windows.Documents.Model.Span spanbox = editor.Document.CaretPosition.GetCurrentSpanBox().AssociatedSpan;
                   if(spanbox.FontWeight==FontWeights.Bold && spanbox.ForeColor==Colors.Aqua)
                       Telerik.Windows.Documents.Model.Section currsect = editor.Document.CaretPosition.GetCurrentSectionBox().AssociatedSection;
                       Telerik.Windows.Documents.Model.Span currspan = editor.Document.CaretPosition.GetCurrentSpanBox().AssociatedSpan;
                       bool check = editor.Document.CaretPosition.MoveToNextInline();
                       bool c=editor.Document.CaretPosition.MoveToNextInline();
                       bool c1=editor.Document.CaretPosition.MoveToNextInline();
                       var documentelement = editor.Document.CaretPosition.GetCurrentParagraphBox();
                       if (documentelement != null && documentelement.GetType() == typeof(Telerik.Windows.Documents.Layout.ParagraphLayoutBox))
                           Telerik.Windows.Documents.Model.Paragraph para = documentelement.AssociatedParagraph;
                           spanbox.Tag = Guid.NewGuid().ToString();
                           string spantext = (para.Inlines.FirstOrDefault() as Telerik.Windows.Documents.Model.Span).Text;
                           if (!string.IsNullOrEmpty(spantext) && spantext == "[@[")
                               NextPara = para.NextSibling as Telerik.Windows.Documents.Model.Paragraph;
                               //var DocEle = new DocumentElementCollection(para);
                               //foreach (var item in para.Children)
                               //    DocEle.Add(item);
                               while (NextPara !=null)
                                   if (NextPara !=null && (NextPara.Inlines.FirstOrDefault() as Telerik.Windows.Documents.Model.Span).Text == "]@]")
                                       //var DocEle2 = new DocumentElementCollection(NextPara);
                                       //foreach (var item in NextPara.Children)
                                       //    DocEle2.Add(item);
                                   //var DocEle1 = new DocumentElementCollection(NextPara);
                                   //foreach (var item in NextPara.Children)
                                   //    DocEle1.Add(item);
                                   NextPara = NextPara.NextSibling as Telerik.Windows.Documents.Model.Paragraph;
               catch (Exception ex)
               { }

  2. Petya
    Petya avatar
    973 posts

    Posted 05 Sep 2013 Link to this post

    Hi Sopan,

    Please refer to the other forum thread you opened with a similar question for an answer on how to delete a table element.

    In general, the proper approach when deleting content from a measured document is to select it and call the Delete() method of RadRichTextBox. Respectively, when inserting content you should move the caret to the desired location and call one of the Insert~() methods of the control.

    I suggest you refer to the Positioning and Selection articles in the online documentation for further information on how to manipulate DocumentSelection.

    I hope this helps!

    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. DevCraft banner
Back to Top