First, I should say that when a document is built using the RadRichTextBoxUI and you insert a table, an empty paragraph is inserted before and after the table and for some reasons related to the document structure we strongly recommend to clients who decide to build their documents from code to do the same.
Other than that, I tried the approach you adopted and accessing the paragraph after a table using the NextSibling property works fine. However, we usually advise clients not to remove elements from the Blocks, Inlines, Children, etc. collections
of the document elements once the document is built as that may cause the invalidation of the document or other problems. As you may have guessed yourself, we recommend using the RadRichTextBox/RadDocument API in such cases in order to ensure that after modifying the document it will still be valid. That said and from what you stated in your post - that the NextSibling property does not work for you and elements don't seem in order, I highly suspect the modifications you made to your document may have caused such issues.
In this regard I would suggest using the Document Position
and Document Selection
approaches when removing from your documents. For example, you can get a move a DocumentPosition to the paragraph after a table as follows:
Table table = tr.EndPosition.GetCurrentTableCellBox().AssociatedTableCell.Row.Table;
Paragraph next = (Paragraph)table.NextSibling;
Once you've successfully selected the required elements (for example - the table and the paragraphs prior and after it), you can call the Delete
method of the document.
Also, I would recommend not to add elements in the collections mentioned above using the AddBefore, AddAfter methods as that may also cause problems. Instead, you can move the CaretPosition
of the document to the desired place and call the Insert
methods. You an also take a look at this article
for information regarding DocumentFragment.
I hope this information is helpful!