Back to Devexpress

ReadOnlyParagraphCollection.Get(DocumentPosition) Method

officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-readonlyparagraphcollection-dot-get-x28-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-documentposition-x29.md

latest6.9 KB
Original Source

ReadOnlyParagraphCollection.Get(DocumentPosition) Method

Gets a paragraph which contains the specified position.

Namespace : DevExpress.XtraRichEdit.API.Native

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

NuGet Package : DevExpress.RichEdit.Core

Declaration

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

Parameters

NameTypeDescription
posDocumentPosition

A DocumentPosition for which an encompassed paragraph is obtained.

|

Returns

TypeDescription
Paragraph

A Paragraph object.

|

Remarks

The Get method returns a Paragraph object which encompasses the specified position.

Note

If you operate with a selection range, the Get method should be enclosed within a DocumentRange.BeginUpdateDocument - DocumentRange.EndUpdateDocument method pair. Otherwise, an incorrect document model might be selected, resulting in an exception “Error: specified document position or range belongs to other document or subdocument” being thrown.

The following code snippets (auto-collected from DevExpress Examples) contain references to the Get(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.

winforms-richedit-layout-api-practical-usage/CS/WindowsFormsApplication1/DocumentLayoutHelper/DocumentElementLayoutHelper.cs#L24

csharp
int currentParagraphIndex = currentDocument.Paragraphs.ToList().IndexOf(currentDocument.Paragraphs.Get(currentDocument.CreatePosition(currentTextBlock.Range.Start)));
returnedInformation += String.Format("Paragrpah index: {0}\r\n", currentParagraphIndex + 1);

winforms-richedit-document-api/CS/RichEditAPISample/CodeExamples/Range.cs#L79

csharp
SubDocument doc = pos.BeginUpdateDocument();
Paragraph par = doc.Paragraphs.Get(pos);
DocumentPosition newPos = doc.CreatePosition(par.Range.End.ToInt() - 1);

wpf-richedit-document-api/CS/DXRichEditControlAPISample/CodeExamples/RangeActions.cs#L79

csharp
SubDocument doc = pos.BeginUpdateDocument();
Paragraph par = doc.Paragraphs.Get(pos);
DocumentPosition newPos = doc.CreatePosition(par.Range.End.ToInt() - 1);

word-document-api-examples/CS/CodeExamples/RangeActions.cs#L93

csharp
SubDocument doc = pos.BeginUpdateDocument();
Paragraph par = doc.Paragraphs.Get(pos);
DocumentPosition newPos = doc.CreatePosition(par.Range.End.ToInt() - 1);

winforms-richedit-layout-api-practical-usage/VB/WindowsFormsApplication1/DocumentLayoutHelper/DocumentElementLayoutHelper.vb#L27

vb
Dim currentParagraphIndex As Integer = currentDocument.Paragraphs.ToList().IndexOf(currentDocument.Paragraphs.Get(currentDocument.CreatePosition(currentTextBlock.Range.Start)))
returnedInformation &= String.Format("Paragrpah index: {0}" & Constants.vbCrLf, currentParagraphIndex + 1)

winforms-richedit-document-api/VB/RichEditAPISample/CodeExamples/Range.vb#L73

vb
Dim doc As DevExpress.XtraRichEdit.API.Native.SubDocument = pos.BeginUpdateDocument()
Dim par As DevExpress.XtraRichEdit.API.Native.Paragraph = doc.Paragraphs.[Get](pos)
Dim newPos As DevExpress.XtraRichEdit.API.Native.DocumentPosition = doc.CreatePosition(par.Range.[End].ToInt() - 1)

wpf-richedit-document-api/VB/DXRichEditControlAPISample/CodeExamples/RangeActions.vb#L71

vb
Dim doc As SubDocument = pos.BeginUpdateDocument()
Dim par As Paragraph = doc.Paragraphs.Get(pos)
Dim newPos As DocumentPosition = doc.CreatePosition(par.Range.End.ToInt() - 1)

word-document-api-examples/VB/CodeExamples/RangeActions.vb#L83

vb
Dim doc As DevExpress.XtraRichEdit.API.Native.SubDocument = pos.BeginUpdateDocument()
Dim par As DevExpress.XtraRichEdit.API.Native.Paragraph = doc.Paragraphs.[Get](pos)
Dim newPos As DevExpress.XtraRichEdit.API.Native.DocumentPosition = doc.CreatePosition(par.Range.[End].ToInt() - 1)

See Also

ReadOnlyParagraphCollection Interface

ReadOnlyParagraphCollection Members

DevExpress.XtraRichEdit.API.Native Namespace