officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-field.md
Returns the range that contains the field code.
Namespace : DevExpress.XtraRichEdit.API.Native
Assembly : DevExpress.RichEdit.v25.2.Core.dll
NuGet Package : DevExpress.RichEdit.Core
DocumentRange CodeRange { get; }
ReadOnly Property CodeRange As DocumentRange
| Type | Description |
|---|---|
| DocumentRange |
The document range occupied by the field code.
|
The following code snippet specifies a custom date and time format for all DATE fields in the document:
using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;
//...
using (RichEditDocumentServer wordProcessor = new RichEditDocumentServer())
{
// Access a document.
Document document = wordProcessor.Document;
// ...
// Check all fields in the document.
for (int i = 0; i < document.Fields.Count; i++)
{
// Access a field code.
string fieldCode = document.GetText(document.Fields[i].CodeRange);
// Check whether a field code is "DATE".
if (fieldCode == "DATE")
{
// Set the document position to the end of the field code range.
DocumentPosition position = document.Fields[i].CodeRange.End;
// Specify a date and time format for the field.
document.InsertText(position, @" \@ ""M/d/yyyy HH:mm:ss""");
}
}
// Update all fields in the main document body.
document.Fields.Update();
}
Imports DevExpress.XtraRichEdit
Imports DevExpress.XtraRichEdit.API.Native
'...
Using wordProcessor As New RichEditDocumentServer()
' Access a document.
Dim document As Document = wordProcessor.Document
' ...
' Check all fields in the document.
For i As Integer = 0 To document.Fields.Count - 1
' Access a field code.
Dim fieldCode As String = document.GetText(document.Fields(i).CodeRange)
' Check whether a field code is "DATE".
If fieldCode = "DATE" Then
' Set the document position to the end of the field code range.
Dim position As DocumentPosition = document.Fields(i).CodeRange.End
' Specify a date and time format for the field.
document.InsertText(position, " \@ ""M/d/yyyy HH:mm:ss""")
End If
Next i
' Update all fields in the main document body.
document.Fields.Update()
End Using
The following code snippets (auto-collected from DevExpress Examples) contain references to the CodeRange property.
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/Field.cs#L41
{
string fieldCode = document.GetText(currentDocument.Fields[i].CodeRange);
if (fieldCode == "DATE")
wpf-richedit-document-api/CS/DXRichEditControlAPISample/CodeExamples/DocumentFieldActions.cs#L34
{
string fieldCode = document.GetText(currentDocument.Fields[i].CodeRange);
if (fieldCode == "DATE")
word-document-api-examples/CS/CodeExamples/FieldActions.cs#L57
// Access a field code.
string fieldCode = document.GetText(document.Fields[i].CodeRange);
winforms-richedit-document-api/VB/RichEditAPISample/CodeExamples/Field.vb#L33
For i As Integer = 0 To currentDocument.Fields.Count - 1
Dim fieldCode As String = document.GetText(currentDocument.Fields(CInt((i))).CodeRange)
If Equals(fieldCode, "DATE") Then
wpf-richedit-document-api/VB/DXRichEditControlAPISample/CodeExamples/DocumentFieldActions.vb#L29
For i As Integer = 0 To currentDocument.Fields.Count - 1
Dim fieldCode As String = document.GetText(currentDocument.Fields(i).CodeRange)
If fieldCode = "DATE" Then
word-document-api-examples/VB/CodeExamples/FieldActions.vb#L49
' Access a field code.
Dim fieldCode As String = document.GetText(document.Fields(CInt((i))).CodeRange)
' Check whether a field code is "DATE".
See Also