Back to Devexpress

Document.ChangeActiveDocument(SubDocument) Method

officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-document-dot-changeactivedocument-x28-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-subdocument-x29.md

latest5.5 KB
Original Source

Document.ChangeActiveDocument(SubDocument) Method

Enables you to operate on selections in documents other than the main document, such as headers and footers.

Namespace : DevExpress.XtraRichEdit.API.Native

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

NuGet Package : DevExpress.RichEdit.Core

Declaration

csharp
void ChangeActiveDocument(
    SubDocument document
)
vb
Sub ChangeActiveDocument(
    document As SubDocument
)

Parameters

NameTypeDescription
documentSubDocument

A SubDocument object that is the document that is different from the currently active document.

|

Remarks

The following code snippet demonstrates how you can select a bookmark in the header. Note that the use of the ChangeActiveDocument is mandatory, otherwise the BookmarkCollection.Select method will fail.

csharp
// Find the bookmark.
SubDocument myDoc = richEditControl1.Document.Sections[0].BeginUpdateHeader(HeaderFooterType.Even);
Bookmark bmark = myDoc.Bookmarks[0];            
richEditControl1.Document.Sections[0].EndUpdateHeader(myDoc);
// Select the bookmark.
SubDocument subDoc = bmark.Range.BeginUpdateDocument();
richEditControl1.Document.ChangeActiveDocument(subDoc);
subDoc.Bookmarks.Select(bmark);
bmark.Range.EndUpdateDocument(subDoc);
vb
' Find the bookmark.
Dim myDoc As SubDocument = richEditControl1.Document.Sections(0).BeginUpdateHeader(HeaderFooterType.Even)
Dim bmark As Bookmark = myDoc.Bookmarks(0)
richEditControl1.Document.Sections(0).EndUpdateHeader(myDoc)
' Select the bookmark.
Dim subDoc As SubDocument = bmark.Range.BeginUpdateDocument()
richEditControl1.Document.ChangeActiveDocument(subDoc)
subDoc.Bookmarks.Select(bmark)
bmark.Range.EndUpdateDocument(subDoc)

The following code snippets (auto-collected from DevExpress Examples) contain references to the ChangeActiveDocument(SubDocument) 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/HeaderAndFooter.cs#L21

csharp
SubDocument headerDocument = firstSection.BeginUpdateHeader();
document.ChangeActiveDocument(headerDocument);
headerDocument.AppendText("Header");

wpf-richedit-document-api/CS/DXRichEditControlAPISample/CodeExamples/HeaderAndFooterActions.cs#L23

csharp
SubDocument headerDocument = firstSection.BeginUpdateHeader();
document.ChangeActiveDocument(headerDocument);
document.CaretPosition = headerDocument.CreatePosition(0);

winforms-richedit-document-api/VB/RichEditAPISample/CodeExamples/HeaderAndFooter.vb#L19

vb
Dim headerDocument As DevExpress.XtraRichEdit.API.Native.SubDocument = firstSection.BeginUpdateHeader()
document.ChangeActiveDocument(headerDocument)
headerDocument.AppendText("Header")

wpf-richedit-document-api/VB/DXRichEditControlAPISample/CodeExamples/HeaderAndFooterActions.vb#L19

vb
Dim headerDocument As SubDocument = firstSection.BeginUpdateHeader()
document.ChangeActiveDocument(headerDocument)
document.CaretPosition = headerDocument.CreatePosition(0)

See Also

Select(Bookmark)

Range

BeginUpdateHeader

BeginUpdateDocument()

Document Interface

Document Members

DevExpress.XtraRichEdit.API.Native Namespace