Back to Devexpress

SubDocument.InsertText(DocumentPosition, String) Method

officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-subdocument-dot-inserttext-x28-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-documentposition-system-dot-string-x29.md

latest8.3 KB
Original Source

SubDocument.InsertText(DocumentPosition, String) Method

Inserts the specified text at the specified position.

Namespace : DevExpress.XtraRichEdit.API.Native

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

NuGet Package : DevExpress.RichEdit.Core

Declaration

csharp
DocumentRange InsertText(
    DocumentPosition pos,
    string text
)
vb
Function InsertText(
    pos As DocumentPosition,
    text As String
) As DocumentRange

Parameters

NameTypeDescription
posDocumentPosition

A DocumentPosition object specifying the position at which the text should be inserted.

| | text | String |

A String value specifying the text to insert.

|

Returns

TypeDescription
DocumentRange

A DocumentRange object representing the DocumentRange.Start and DocumentRange.End positions of the inserted text.

|

Remarks

Consider using the SubDocument.InsertSingleLineText method instead of InsertText for inserting text without line breaks. This can enhance performance.

Example

View Example

csharp
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);
vb
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 InsertText(DocumentPosition, String) 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/Table.cs#L17

csharp
// Create a table header.
document.InsertText(tbl[0, 0].Range.Start, "Name");
document.InsertText(tbl[0, 1].Range.Start, "Size");

wpf-richedit-document-api/CS/DXRichEditControlAPISample/CodeExamples/TableActions.cs#L21

csharp
// Create a table header.
document.InsertText(tbl[0, 0].Range.Start, "Name");
document.InsertText(tbl[0, 1].Range.Start, "Size");

word-document-api-examples/CS/CodeExamples/ContentControlsActions.cs#L28

csharp
var nameTextPosition = document.CreatePosition(nameControl.Range.Start.ToInt() + 1);
document.InsertText(nameTextPosition, "Click to enter a name");

winforms-richedit-tables-simple-example/CS/TablesSimpleExample/Form1.cs#L116

csharp
// Insert the customer info
document.InsertText(table[3, 2].Range.Start, "Ryan Anita W");
document.InsertText(table[3, 3].Range.Start, "Intermediate");

word-document-api-table-examples/CS/Program.cs#L96

csharp
//Insert the customer info
document.InsertText(table[3, 1].Range.Start, "Ryan Anita W");
document.InsertText(table[3, 2].Range.Start, "Intermediate");

winforms-richedit-document-api/VB/RichEditAPISample/CodeExamples/Table.vb#L16

vb
' Create a table header.
document.InsertText(tbl(CInt((0)), CInt((0))).Range.Start, "Name")
document.InsertText(tbl(CInt((0)), CInt((1))).Range.Start, "Size")

wpf-richedit-document-api/VB/DXRichEditControlAPISample/CodeExamples/TableActions.vb#L18

vb
' Create a table header.
document.InsertText(tbl(0, 0).Range.Start, "Name")
document.InsertText(tbl(0, 1).Range.Start, "Size")

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

vb
' and access the range of the inserted text.
Dim range2 As DocumentRange = document.InsertText(range1.End, ">>NewText<<")

winforms-richedit-tables-simple-example/VB/TablesSimpleExample/Form1.vb#L94

vb
' Insert the customer info
document.InsertText(table(3, 2).Range.Start, "Ryan Anita W")
document.InsertText(table(3, 3).Range.Start, "Intermediate")

word-document-api-table-examples/VB/Program.vb#L75

vb
'Insert the customer info
document.InsertText(table(3, 1).Range.Start, "Ryan Anita W")
document.InsertText(table(3, 2).Range.Start, "Intermediate")

See Also

InsertSingleLineText(DocumentPosition, String)

InsertRtfText

SubDocument Interface

SubDocument Members

DevExpress.XtraRichEdit.API.Native Namespace