officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-subdocument-dot-createrange-x28-system-dot-int32-system-dot-int32-x29.md
Creates a new document range using the specified start position and range length.
Namespace : DevExpress.XtraRichEdit.API.Native
Assembly : DevExpress.RichEdit.v25.2.Core.dll
NuGet Package : DevExpress.RichEdit.Core
DocumentRange CreateRange(
int start,
int length
)
Function CreateRange(
start As Integer,
length As Integer
) As DocumentRange
| Name | Type | Description |
|---|---|---|
| start | Int32 |
An integer value specifying the start position.
| | length | Int32 |
An integer value specifying the range length.
|
| Type | Description |
|---|---|
| DocumentRange |
A DocumentRange object.
|
| Type | Description |
|---|---|
| ArgumentException |
Throws if the negative value is passed as the start parameter.
|
The code sample below obtains a range and calls the SubDocument.InsertText method to insert a text as follows:
ABNewTextCDEFGH
Range r1 starts at 1, ends at 11
Range r2 starts at 2, ends at 9
Document document = wordProcessor.Document;
document.AppendText("ABCDEFGH");
DocumentRange r1 = document.CreateRange(1, 3);
DocumentPosition pos1 = document.CreatePosition(2);
DocumentRange r2 = document.InsertText(pos1, ">>NewText<<");
string s1 = String.Format("Range r1 starts at {0}, ends at {1}", r1.Start, r1.End);
string s2 = String.Format("Range r2 starts at {0}, ends at {1}", r2.Start, r2.End);
document.Paragraphs.Append();
document.AppendText(s1);
document.Paragraphs.Append();
document.AppendText(s2);
Dim document as Document = wordProcessor.Document
document.AppendText("ABCDEFGH")
Dim r1 As DocumentRange = document.CreateRange(1, 3)
Dim pos1 As DocumentPosition = document.CreatePosition(2)
Dim r2 As DocumentRange = document.InsertText(pos1, ">>NewText<<")
Dim s1 As String = String.Format("Range r1 starts at {0}, ends at {1}", r1.Start, r1.End)
Dim s2 As String = String.Format("Range r2 starts at {0}, ends at {1}", r2.Start, r2.End)
document.Paragraphs.Append()
document.AppendText(s1)
document.Paragraphs.Append()
document.AppendText(s2)
The following code snippets (auto-collected from DevExpress Examples) contain references to the CreateRange(Int32, Int32) 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-document-api/CS/RichEditAPISample/CodeExamples/SelectionCollection.cs#L16
int endPos = document.Tables[0].Rows[1].LastCell.ContentRange.Start.ToInt();
DocumentRange myRange = document.CreateRange(startPos, endPos - startPos);
document.Selections.Add(myRange);
word-document-api-examples/CS/CodeExamples/RangeActions.cs#L28
// Create the first document range.
DocumentRange range1 = document.CreateRange(1, 3);
winforms-richeditcontrol-common-api/CS/RichEditAPISample/Form1.cs#L489
if(delimiter.Length > 0) {
e.Code = codeEditor.CurrentCodeEditor.Document.GetText(codeEditor.CurrentCodeEditor.Document.CreateRange(0, delimiter[0].Start.ToInt()));
e.AdditionalModules = codeEditor.CurrentCodeEditor.Document.GetText(codeEditor.CurrentCodeEditor.Document.CreateRange(delimiter[0].End.ToInt(), codeEditor.CurrentCodeEditor.Document.Range.End.ToInt() - delimiter[0].End.ToInt()));
wpf-richedit-document-api/CS/DXRichEditControlAPISample/CodeExamples/RangeActions.cs#L33
document.AppendText("ABCDEFGH");
DocumentRange r1 = document.CreateRange(1, 3);
DocumentPosition pos1 = document.CreatePosition(2);
office-file-api-ai-implementation/CS/Controllers/ProofreadController.cs#L37
var fixedRange = wordProcessor.DocumentLayout.GetPage(0).MainContentRange;
var pageRange = wordProcessor.Document.CreateRange(fixedRange.Start, fixedRange.Length); // Translate the first page
await docProcessingService.ProofreadAsync(pageRange, cultureInfo);
winforms-richedit-document-api/VB/RichEditAPISample/CodeExamples/SelectionCollection.vb#L15
Dim endPos As Integer = document.Tables(CInt((0))).Rows(CInt((1))).LastCell.ContentRange.Start.ToInt()
Dim myRange As DevExpress.XtraRichEdit.API.Native.DocumentRange = document.CreateRange(startPos, endPos - startPos)
document.Selections.Add(myRange)
word-document-api-examples/VB/CodeExamples/RangeActions.vb#L29
' Create the first document range.
Dim range1 As DocumentRange = document.CreateRange(1, 3)
winforms-richeditcontrol-common-api/VB/RichEditAPISample/Form1.vb#L485
If delimiter.Length > 0 Then
e.Code = codeEditor.CurrentCodeEditor.Document.GetText(codeEditor.CurrentCodeEditor.Document.CreateRange(0, delimiter(0).Start.ToInt()))
e.AdditionalModules = codeEditor.CurrentCodeEditor.Document.GetText(codeEditor.CurrentCodeEditor.Document.CreateRange(delimiter(0).End.ToInt(), codeEditor.CurrentCodeEditor.Document.Range.End.ToInt() - delimiter(0).End.ToInt()))
wpf-richedit-document-api/VB/DXRichEditControlAPISample/CodeExamples/RangeActions.vb#L28
document.AppendText("ABCDEFGH")
Dim r1 As DocumentRange = document.CreateRange(1, 3)
Dim pos1 As DocumentPosition = document.CreatePosition(2)
word-processing-merge-documents-with-different-headers-and-footers/VB/Helpers/SectionsMerger.vb#L33
' Delete empty paragraphs
Dim emptyParagraph As DocumentRange = target.CreateRange(target.Range.End.ToInt() - 1, 1)
target.Delete(emptyParagraph)
See Also