Back to Devexpress

ParagraphCollection.Insert(DocumentPosition) Method

officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-paragraphcollection-dot-insert-x28-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-documentposition-x29.md

latest6.5 KB
Original Source

ParagraphCollection.Insert(DocumentPosition) Method

Inserts a new Paragraph at a specified position.

Namespace : DevExpress.XtraRichEdit.API.Native

Assembly : DevExpress.RichEdit.v25.2.Core.dll

NuGet Package : DevExpress.RichEdit.Core

Declaration

csharp
Paragraph Insert(
    DocumentPosition pos
)
vb
Function Insert(
    pos As DocumentPosition
) As Paragraph

Parameters

NameTypeDescription
posDocumentPosition

A DocumentPosition object that specifies a position to insert a new paragraph.

|

Returns

TypeDescription
Paragraph

A paragraph that follows the inserted paragraph.

|

Remarks

The code sample below appends a paragraph and inserts a paragraph at the start of the second section:

csharp
using DevExpress.XtraRichEdit.API.Native;

using (RichEditDocumentServer wordProcessor = new RichEditDocumentServer())
{
    wordProcessor.LoadDocument("FirstLook.docx");
    Document document = wordProcessor.Document;
    document.BeginUpdate();

    //Append paragraph:
    Paragraph appendedParagraph = document.Paragraphs.Append();
    document.InsertText(appendedParagraph.Range.Start, "Appended paragraph");

    //Insert paragraph at the start of the second section:
    Paragraph paragraph = document.Paragraphs.Insert(document.Sections[1].Range.Start);
    document.InsertText(document.Paragraphs[paragraph.Index - 1].Range.Start,
         "Inserted paragraph");
    document.EndUpdate();
}
vb
Imports DevExpress.XtraRichEdit.API.Native

Using wordProcessor As New RichEditDocumentServer()
    wordProcessor.LoadDocument("FirstLook.docx")
    Dim document As Document = wordProcessor.Document
    document.BeginUpdate()

    'Append paragraph:
    Dim appendedParagraph As Paragraph = document.Paragraphs.Append()
    document.InsertText(appendedParagraph.Range.Start, "Appended paragraph")

    'Insert paragraph at the start of the second section:
    document.InsertText(document.Paragraphs[paragraph.Index - 1].Range.Start
         "Inserted paragraph");
    document.InsertText(paragraph.Range.Start, "Inserted paragraph")
    document.EndUpdate()
End Using

The following code snippets (auto-collected from DevExpress Examples) contain references to the Insert(DocumentPosition) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

word-document-api-examples/CS/CodeExamples/CommentsActions.cs#L128

csharp
// Insert a text to the comment.
commentDocument.Paragraphs.Insert(commentDocument.Range.Start);
commentDocument.InsertText(commentDocument.Range.Start, "some text");

winforms-richedit-document-api/CS/RichEditAPISample/CodeExamples/Shapes.cs#L84

csharp
DocumentRange newRange = boxedDocument.AppendDocumentContent(document.Paragraphs[1].Range);
boxedDocument.Paragraphs.Insert(newRange.Start);

wpf-richedit-document-api/CS/DXRichEditControlAPISample/CodeExamples/ShapesActions.cs#L93

csharp
DocumentRange newRange = boxedDocument.AppendDocumentContent(document.Paragraphs[1].Range);
boxedDocument.Paragraphs.Insert(newRange.Start);
// Insert an image form the main document into the text box.

word-document-api-examples/VB/CodeExamples/CommentsActions.vb#L106

vb
' Insert a text to the comment.
commentDocument.Paragraphs.Insert(commentDocument.Range.Start)
commentDocument.InsertText(commentDocument.Range.Start, "some text")

winforms-richedit-document-api/VB/RichEditAPISample/CodeExamples/Shapes.vb#L76

vb
Dim newRange As DevExpress.XtraRichEdit.API.Native.DocumentRange = boxedDocument.AppendDocumentContent(document.Paragraphs(CInt((1))).Range)
boxedDocument.Paragraphs.Insert(newRange.Start)
' Insert an image form the main document into the text box.

wpf-richedit-document-api/VB/DXRichEditControlAPISample/CodeExamples/ShapesActions.vb#L83

vb
Dim newRange As DocumentRange = boxedDocument.AppendDocumentContent(document.Paragraphs(1).Range)
boxedDocument.Paragraphs.Insert(newRange.Start)
' Insert an image form the main document into the text box.

See Also

ParagraphCollection Interface

ParagraphCollection Members

DevExpress.XtraRichEdit.API.Native Namespace